问题描述
在终端中,我执行了一个主父进程,该进程将派生一个子进程.在父进程和子进程中,我都实现了SIGINT信号处理程序.因此,当我按"ctrl + c"时,是否会同时调用两个处理程序?还是我需要在父进程的处理程序中显式调用子进程的信号处理程序?
In the terminal, I executed a main parent process which will fork a child process. In both the parent and child processes I implemented a SIGINT signal handler.So when I press "ctrl+c", will both the handlers be called at the same time? Or do I need to call the child process's signal handler explicitly in the parent process's handler?
我看了这篇文章: Ctrl-C如何终止子进程?表示" SIGINT信号由终端线路规则生成,并广播到终端的前景进程组中的所有进程".我只是不太了解前台流程组"的含义.
I looked up this post:How does Ctrl-C terminate a child process?which says that "The SIGINT signal is generated by the terminal line discipline, and broadcast to all processes in the terminal's foreground process group". I just didn't quite understand what does "foreground process group" means.
谢谢
推荐答案
是的,他们俩都将获得SIGINT
.
Yes, they both will receive SIGINT
.
调用"另一个进程的信号处理程序没有任何意义.如果两个进程都安装了处理程序,则一旦它们收到信号SIGINT
,它们就会被调用.
"Calling" another process' signal handler doesn't make sense. If the both the process have a handler installed then they will be called once they receive the signal SIGINT
.
通常,与控制终端关联的进程是前台进程,其进程组称为前台进程组.从命令行启动进程时,它是前台进程:
Typically, a process associated with a controlling terminal is foreground process and its process group is called foreground process group. When you start a process from the command line, it's a foreground process:
例如
$ ./script.sh # foreground process
$ ./script & # background process
我建议您阅读有关 tty
和 The TTY demystified
.
I suggest you read about tty
and The TTY demystified
for a detailed explanation.
这篇关于ctrl + c会将SIGINT信号发送到Linux中的父进程和子进程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!