Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何中断生成的脚本?_Bash_Makefile_Copy Paste_Interrupt - Fatal编程技术网

Bash 如何中断生成的脚本?

Bash 如何中断生成的脚本?,bash,makefile,copy-paste,interrupt,Bash,Makefile,Copy Paste,Interrupt,如何使Ctrl-C中断生成生成的脚本 我的make对象生成一个脚本。当它运行时,我按Ctrl-C来中断它,但对它没有影响。我必须执行Ctrl-Z来暂停进程,然后杀死%。有没有办法用Ctrl-C中断脚本 我的Makefile中有以下内容: run: bash -c "trap 'trap - SIGINT SIGTERM ERR; exit 1' SIGINT SIGTERM ERR; $(MAKE) run_int" run_int: $(MAKE) simulate simulate: -

如何使Ctrl-C中断生成生成的脚本

我的make对象生成一个脚本。当它运行时,我按Ctrl-C来中断它,但对它没有影响。我必须执行Ctrl-Z来暂停进程,然后杀死%。有没有办法用Ctrl-C中断脚本

我的Makefile中有以下内容:

run:
bash -c "trap 'trap - SIGINT SIGTERM ERR; exit 1' SIGINT SIGTERM ERR; $(MAKE) run_int"

run_int:
$(MAKE) simulate

simulate:
-$(CALL_TOOL)

CALL_TOOL = external_tool <options>
运行:
bash-c“trap”trap-SIGINT SIGTERM ERR;退出1“SIGINT SIGTERM ERR;$(MAKE)run_int”
运行时间:
$(使)模拟
模拟:
-$(调用工具)
调用工具=外部工具

这不是
make
问题,而是通过
make
启动的
外部程序之一。大概它捕获并忽略了
SIGINT

您可以通过替换makefile中的
external\u工具
来满足自己的需求,例如,
sleep 30
。如果然后从终端运行
make
,您会发现Ctrl-C(在该终端中)会中断
睡眠的执行
很好:

还要注意,您的
运行
规则是没有意义的。只有当信号被传递到定义陷阱的shell时,陷阱SIGINT才是相关的,而事实并非如此。它将被传递到前台进程,这将是由
simulate
规则启动的进程,除非您的Ctrl-C键速度超人。您可以完全删除该规则,并且仍然中断由
simulate
规则运行的进程。如前所述,该过程如何响应信号是一个单独的问题

$ make
bash -c "trap 'trap - SIGINT SIGTERM ERR; exit 1' SIGINT SIGTERM ERR; make run_int"
make[1]: Entering directory `/home/jb/tmp'
make simulate
make[2]: Entering directory `/home/jb/tmp'
sleep 10
^Cmake[2]: *** [simulate] Interrupt
make[1]: *** [run_int] Interrupt
make: *** [run] Error 1