[英]how do I kill this bash script?
I have written a bash script, A, that is calling another script, B, over 1000 times in a loop. 我编写了一个bash脚本A,它在循环中调用另一个脚本B超过1000次。
Ctrl + C kills only script B, only one iteration. Ctrl + C仅杀死脚本B,只杀死一次。 Script A keeps running and calling script B again.
脚本A继续运行并再次调用脚本B.
Can I rewrite something in these scripts so that Ctrl + C will kill script A? 我可以在这些脚本中重写一些内容,以便Ctrl + C会杀死脚本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
. 然后当你按
Ctrl-C
时它们都会得到SIGINT
信号。
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.
如果执行脚本A的shell认为它(shell)是交互式的,则可能发生这种情况。 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.
很难从你的描述中得到更多信息 - 随意粘贴一些示例代码(并描述如何启动脚本),我们将看一看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.