mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
This allows us to maintain GoDoc in a single place, and for "Kill" and "Alive" to have consistent error-handling (Windows does not support negative process-IDs). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
30 lines
908 B
Go
30 lines
908 B
Go
package process
|
|
|
|
import "fmt"
|
|
|
|
// Alive returns true if process with a given pid is running.
|
|
//
|
|
// It only considers positive PIDs; 0 (all processes in the current process
|
|
// group), -1 (all processes with a PID larger than 1), and negative (-n,
|
|
// all processes in process group "n") values for pid are never considered
|
|
// to be alive.
|
|
func Alive(pid int) bool {
|
|
if pid < 1 {
|
|
return false
|
|
}
|
|
return alive(pid)
|
|
}
|
|
|
|
// Kill force-stops a process. It only allows positive PIDs; 0 (all processes
|
|
// in the current process group), -1 (all processes with a PID larger than 1),
|
|
// and negative (-n, all processes in process group "n") values for pid producs
|
|
// an error. Refer to [KILL(2)] for details.
|
|
//
|
|
// [KILL(2)]: https://man7.org/linux/man-pages/man2/kill.2.html
|
|
func Kill(pid int) error {
|
|
if pid < 1 {
|
|
return fmt.Errorf("invalid PID (%d): only positive PIDs are allowed", pid)
|
|
}
|
|
return kill(pid)
|
|
}
|