Consider the following situation:
- I use
fork()
to create a child process from my program - Parent process receives the PID as
1234
. - Child process then calls
execvp("myotherprogram", some_args);
myotherprogram
is expected to run indefinitely until it receives SIGTERM (or higher), but, under some circumstances (e.g. missing file) it will just print an error and abort.
When the parent process receives an event, it wants to kill the child process again by calling:
const int kill_result = kill(1234, SIGTERM);
If myotherprogram
exited early, is kill(1234, SIGTERM)
going to be safe, or can the OS recycle the PID and I potentially kill a random process?