Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send SIGINT to a shell script? [duplicate]

Tags:

bash

shell

unix

I am writing a daemon with more than one process. once the first process is complete then it stops and needs mannual interrupt SIGINT(CTRL + C). After this next script is run.

Process 1 ended successfully.

How can add a SIGINT to proceed it further automatically ?

The question may be trivial but could only find how can we trap a given signal in a script, but how do we add one after completion of a task ?

like image 877
krishnakant Avatar asked Oct 19 '22 01:10

krishnakant


1 Answers

You can kill the current bash shell and all of its children with the command kill -TERM -$$.

Edit:

If, for example, you are launching processes like:

process1 &
process2 &
process3 &
process4

To modify it so that when any process ends it kills all the others you can use:

( process1 ; kill -TERM -$$ ) &
( process2 ; kill -TERM -$$ ) &
( process3 ; kill -TERM -$$ ) &
process4 ; kill -TERM -$$
like image 181
ccarton Avatar answered Dec 07 '22 03:12

ccarton