Check if process exists given its pid

后端 未结 6 1275
孤独总比滥情好
孤独总比滥情好 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:34

    ps -p $PID > /dev/null 2>&1;   echo $?
    

    This command return 0 if process with $PID is still running. Otherwise it returns 1.

    One can use this command in OSX terminal too.

提交回复
热议问题