Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill process when father process ends with Control+C

Tags:

c

linux

process

I have a program with two processes. One of them could terminate or exit because an exception. While i'm testing the program I finish it using Control+c but the child process is still running.

Is there any option to kill the process when I push control+c or when the father process terminates.

like image 366
Jorge Vega Sánchez Avatar asked May 24 '26 17:05

Jorge Vega Sánchez


1 Answers

There's no option to automate this however you can code your applications to support it. A pre-requisite is that the process which wants the other to terminate must have its process id; this is the value the parent receives back from a fork() call.

Give each process a signal handler for SIGINT - when control-C is pressed, SIGINT is sent to the process. In this signal handler, send the signal to your other process and then exit().

like image 200
mah Avatar answered May 27 '26 07:05

mah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!