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()
?
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.
There's no way (that I know of) when using system()
. Besides, with system()
there's the additional step of launching a shell which will execute your command, making this a tad more difficult. You're probably better off replacing it with fork()
and exec()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With