check is Process is Alive from PID while handling recycled PID
0
votes
2
answers
1846
views
From what I seen online you call kill method in c++ in order to see if the process is alive. the issue with that is PID's get rycled and the same PID your looking for may not be the same process. I have a program that has two processes that are not children of each other. The only way to communicate with them is IPC. I would like my host process to shutdown when the client process shuts down. In order to do that I have to know when the client's process is no longer alive.
In Windows, they have what's called a process handler that will reserve the PID from getting recycled until the process that created the handle is closed. I am wondering how to achieve this for macOS/Linux (POSIX) systems.
The problematic code as PID's are reycled.
if (0 == kill(pid, 0))
{
// Process exists.
}
Asked by joseph lake
(11 rep)
Jun 10, 2023, 09:03 AM
Last activity: Jun 13, 2023, 04:09 AM
Last activity: Jun 13, 2023, 04:09 AM