I am on Centos 4 and am using kill(pid, 0) in my C++ program to check whether there is presently a process running with the given pid. I am beginning to suspect that there is a race condition whereby shortly after a process has started, there is a small window of time wherein the kill(pid, 0) does not return zero even though there is actually a process running.
Is this a known issue? Will kill() ever return non-zero when a pid actually exists but has just been started? If kill() is not a reliable to test for existence, is there a better way to perform this test?
kill(pid, 0)will only return 0 if the process exists and you would be able to send it a signal. If the process isn’t running as you (and you aren’t root), then the call will fail with -EPERM.