I wrote a program that forks some processes with fork(). I want to kill all child- and the mother process if there is an error. If I use exit(EXIT_FAILURE) only the child process is killed.
I am thinking about a system(“killall [program_name]”) but there must be a better way…
Thank you all!
Lennart
Under UNIX, send SIGTERM, or SIGABRT, or SIGPIPE or sth. alike to the mother process. This signal will then be propagated to all clients automatically, if they do not explicitely block or ignore it.
Use
getppid()to get the PID to send the signal to, andkill()to send the signal.Remarks:
1. Using
systemis evil. Use internal functions to send signals.2.
killallwould be even more evil. Consider several instances of your program running at once.