Check if process exists given its pid

后端 未结 6 1282
孤独总比滥情好
孤独总比滥情好 2020-12-01 02:06

Given the pid of a Linux process, I want to check, from a C program, if the process is still running.

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 02:46

    You can issue a kill(2) system call with 0 as the signal.

    There's nothing unsafe about kill -0. The program must be aware that the result can become obsolete at any time (including that the pid can get reused before kill is called), that's all. And using procfs instead does use the pid too, and doing so in a more cumbersome and nonstandard way.

提交回复
热议问题