本文介绍了为什么SIGINT可以在终端停止庆典而不是通过kill -INT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我运行通过这样

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 13:01