mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
pkg/process: call out that "Zombie" is only supported on Linux
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
24
pkg/process/process_linux.go
Normal file
24
pkg/process/process_linux.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package process
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func zombie(pid int) (bool, error) {
|
||||
if pid < 1 {
|
||||
return false, nil
|
||||
}
|
||||
data, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
if cols := bytes.SplitN(data, []byte(" "), 4); len(cols) >= 3 && string(cols[2]) == "Z" {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
7
pkg/process/process_nolinux.go
Normal file
7
pkg/process/process_nolinux.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build !linux
|
||||
|
||||
package process
|
||||
|
||||
func zombie(pid int) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
@@ -3,9 +3,7 @@
|
||||
package process
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -47,20 +45,9 @@ func kill(pid int) error {
|
||||
// a PID larger than 1), and negative (-n, all processes in process group "n")
|
||||
// values for pid are ignored. Refer to [PROC(5)] for details.
|
||||
//
|
||||
// Zombie is only implemented on Linux, and returns false on all other platforms.
|
||||
//
|
||||
// [PROC(5)]: https://man7.org/linux/man-pages/man5/proc.5.html
|
||||
func Zombie(pid int) (bool, error) {
|
||||
if pid < 1 {
|
||||
return false, nil
|
||||
}
|
||||
data, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
if cols := bytes.SplitN(data, []byte(" "), 4); len(cols) >= 3 && string(cols[2]) == "Z" {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
return zombie(pid)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user