tags:

views:

67

answers:

2

I have written a bash script, A, that is calling another script, B, over 1000 times in a loop.

Ctrl+C kills only script B, only one iteration. Script A keeps running and calling script B again.

Can I rewrite something in these scripts so that Ctrl+C will kill script A?

+2  A: 

Hello, you can trap your killing signal and do whatever you want (killing A instead of B, for instance). See here how. If you use it in B, try making it kill its parent...

greg0ire
A: 

The correct thing to do is to ensure that both scripts are executed in the same process group. Then they both will get SIGINT signal when you press Ctrl-C.

From what you tell, for some reason they got into the different process groups. This may happen if the shell which executes script A thinks that it (the shell) is interactive. It's hard to tell more from your description -- feel free to paste some sample code (and describe how you launch the scripts) and we'll take a look.

Roman Cheplyaka