问题描述
我注意到,当我运行通过这样
I noticed that when I am running a hanging process via bash script like this
foo.sh:
sleep 999
如果我通过命令来运行它,和preSS按Ctrl + C
If I run it via command, and press Ctrl+C
./foo.sh
^C
睡眠将被中断。然而,当我尝试使用SIGINT杀死它
The sleep will be interrupted. However, when I try to kill it with SIGINT
ps aux | grep foo
kill -INT 12345 # the /bin/bash ./foo.sh process
那么它看起来像bash和睡眠忽略SIGINT和保持运行。这让我吃惊。我想按Ctrl + C是实际发送SIGINT到前台进程,那么,为什么是行为以不同的方式按Ctrl + C终端和杀死-INT?
Then it looks like bash and sleep ignores the SIGINT and keep running. This surprises me. I thought Ctrl + C is actually sending SIGINT to the foreground process, so why is that behaviors differently for Ctrl + C in terminal and kill -INT?
推荐答案
控制骨节病> C 骨节病>实际发送 SIGINT
来前台进程的集团的(它由庆典
工艺,和睡眠
工艺) 。做同样以杀
命令,将信号发送到进程组,例如:
actually sends SIGINT
to the foreground process group (which consists of a bash
process, and a sleep
process). To do the same with a kill
command, send the signal to the process group, e.g:
kill -INT -12345
这篇关于为什么SIGINT可以在终端停止庆典而不是通过kill -INT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!