How do I wait for PID X to exit if X is not a child process?

c, linux

Solution

See this answer by chaos:

The usual practice is to poll using kill(0, pid) and looking for return value -1 and errno of ESRCH to indicate that the process is gone

Based on the man page for kill, it might be `kill(pid,0)` instead. But the idea is the same.

Problem

using c how do I wait for PID X to exit when it is not a child of my current process? ``` Kill(pid, SIGTERM); waitpid(pid,NULL,0); ``` The above does not work as 'pid' is not a child process.

Original source

Related problems