Check if a process exists in go way

后端 未结 7 1839
甜味超标
甜味超标 2020-12-31 02:29

If I have the PID of a process, is os.FindProcess enough to test for the existing of the process? I mean if it returns err can I assume that it\'s terminated (o

7条回答
  •  别那么骄傲
    2020-12-31 02:30

    You can also just use syscall.Kill. It amounts to less code.

    killErr := syscall.Kill(pid, syscall.Signal(0))
    procExists := killErr == nil
    

提交回复
热议问题