pkg/system: IsProcessZombie() ignore "os.ErrNotExist" errors
If the file doesn't exist, the process isn't running, so we should be able to ignore that. Also remove an intermediate variable. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
8d6da1e100
commit
970ad4e3c7
2 changed files with 4 additions and 4 deletions
|
@ -355,7 +355,6 @@ func killProcessDirectly(container *container.Container) error {
|
|||
if system.IsProcessAlive(pid) {
|
||||
// Since we can not kill a zombie pid, add zombie check here
|
||||
isZombie, err := system.IsProcessZombie(pid)
|
||||
// TODO(thaJeztah) should we ignore os.IsNotExist() here? ("/proc/<pid>/stat" will be gone if the process exited)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("container", container.ID).Warn("Container state is invalid")
|
||||
return err
|
||||
|
|
|
@ -29,10 +29,11 @@ func KillProcess(pid int) {
|
|||
// IsProcessZombie return true if process has a state with "Z"
|
||||
// http://man7.org/linux/man-pages/man5/proc.5.html
|
||||
func IsProcessZombie(pid int) (bool, error) {
|
||||
statPath := fmt.Sprintf("/proc/%d/stat", pid)
|
||||
dataBytes, err := os.ReadFile(statPath)
|
||||
dataBytes, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid))
|
||||
if err != nil {
|
||||
// TODO(thaJeztah) should we ignore os.IsNotExist() here? ("/proc/<pid>/stat" will be gone if the process exited)
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
data := string(dataBytes)
|
||||
|
|
Loading…
Reference in a new issue