github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/monitor/internal/k8s/runtime_cache_linux.go (about)

     1  // +build linux
     2  
     3  package k8smonitor
     4  
     5  import (
     6  	"syscall"
     7  )
     8  
     9  // syscallKill points to syscall.Kill and can be overwritten in unit tests
    10  var syscallKill func(pid int, sig syscall.Signal) (err error) = syscall.Kill
    11  
    12  func sandboxIsRunning(pid int) (bool, error) {
    13  	if err := syscallKill(pid, syscall.Signal(0)); err != nil {
    14  		// the expected error is ESRCH: The process or process group does not exist.
    15  		if err != syscall.ESRCH {
    16  			return false, err
    17  		}
    18  
    19  		// this is a successful check that the process is dead
    20  		// and therefore the sandbox is not running anymore
    21  		return false, nil
    22  	}
    23  
    24  	// otherwise it means that the process is not dead and is still running
    25  	return true, nil
    26  }