在终端中,我执行了一个主父进程,它将分叉子进程.在父进程和子进程中,我实现了一个SIGINT信号处理程序.
所以当我按“ctrl c”时,两个处理程序是否同时被调用?或者我是否需要在父进程的处理程序中显式调用子进程的信号处理程序?
我查了一下这篇文章:
How does Ctrl-C terminate a child process?
其中说“SIGINT信号由终端线路规则生成,并广播到终端的前台进程组中的所有进程”.我只是不太明白“前台进程组”是什么意思.
谢谢,
解决方法:
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?
是的,他们都会收到SIGINT.
Or do I need to call the child process’s signal handler explicitly in
the parent process’s handler?
“调用”另一个进程’信号处理程序没有意义.如果进程都安装了一个处理程序,那么一旦收到信号SIGINT就会调用它们.
I just didn’t quite understand what does “foreground process group”
means.
通常,与控制终端相关联的进程是前台进程,其进程组称为前台进程组.从命令行启动进程时,它是一个前台进程:
例如.
$./script.sh # foreground process
$./script & # background process
标签:linux,fork,signals
来源: https://codeday.me/bug/20191006/1858657.html