In my process I need to start/restart another process.
Currently I use a thread with a tiny stack size and the following code:
usleep(1000 * 1000);
One problematic piece is restarting immediately: if the child process fails to start that is going to cause 100% CPU usage. It may be a transient error in the child process (e.g. cannot connect to a server). It may be a good idea to add a least one second pause before trying to restart.
system call does on Linux is:
SIGQUITto be ignored.
exec()shell, passing the command line to the shell.
waitpid()that blocks the thread till the child process terminates.
If you were to re-implement the functionality of
system you would probably omit step 5 (along with steps 1, 2 and 6) to avoid blocking the thread and rely on
SIGCHLD to get notified when the child process has terminated and needs to be restarted.
In other words, the bare minimum would be to set up a signal handler for
SIGCHLD and call