I want to know if a process on my computer exists. There are three ways to test this through code in C: kill, getpid (pid) ,stat (path, & stat)
I want to know what are the pros and cons of each method?
I want to know if a process on my computer exists. There are three ways to test this through code in C: kill, getpid (pid) ,stat (path, & stat)
I want to know what are the pros and cons of each method?
kill(pid, 0)
is POSIX compliant whereas stat("/proc/<pid>", ...)
is not.
I don't know what you mean with getpid()
as it doesn't take any parameters.
Update:
getpgid(pid)
is POSIX compliant as well, so I don't think there's a difference between using kill
and getpgid
for your purpose. I would choose kill
because it's more widely used.