R – Get the child PID after system()

execforklinux

As far as I understand, the system() call uses internally fork() and exec() but encapsulates them for a easier handling.

Is it possible to get the PID from the child process created with the system() call?

Aim: I want to be able to SIGINT any child process after a certain timeout. I could rebuild the system() function by using fork() and exec(). But all I need is the child's PID and perhaps there is shortcut by using system()?

Best Answer

Typically, system() is a synchronous operation. This means it won't return until the child has exited, i.e. there is no valid PID for the child process when system() returns, since the child process no longer exists.

Related Topic