SIG_IGN忽略SIGINT信号失败
SIG_IGN fails to ignore SIGINT signal
我有一个主进程和一些子进程从中衍生。在一个时间点,我必须给SIGINT信号所有的子进程,但不给主进程。我无法为所有子进程存储pid。所以我使用SIG_IGN来忽略主进程中的SIGINT,并在我的操作后设置为默认值。但这并没有奏效。
请查看下面的代码片段:
/* Find group id for process */
nPgid = getpgid(parentPID);
/* Ignore SIGINT signal in parent process */
if (signal(SIGINT, SIG_IGN) == SIG_ERR)
{
cout << "Error in ignoring signal n");
}
/* Send SIGINT signal to all process in the group */
nReturnValue = kill ( (-1 * nPgid), SIGINT);
if (nReturnValue == RETURN_SUCCESS)
{
cout << "Sent SIGINT signal to all process in group successfully n";
}
else
{
cout << "Alert!!! Unable to send SIGINT signal to all process in the group n";
}
/* Set SIGINT signal status to default */
signal (SIGINT, SIG_DFL);
sleep(2);
我没有得到任何错误。但是父母要被杀了。我做错什么了吗?
nPgid = getpgid(parentPID);
parentPID
是什么?通过0
或getpid()
的结果得到主叫进程的组。
From man getpgid()
:
getpgid()返回pid指定的进程的PGID。如果pid为0,则使用调用进程的进程ID。(检索很少需要调用者以外的进程的PGID,并且POSIX.1 getpgrp()优先用于该任务。
从上面这篇文章我得出结论要做
nPgid = getpgid(o);
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- Qt VTK交互风格的信号到小部件
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- Qt C++:静态断言失败:信号和插槽参数不兼容
- Windows高速模式(C++):等待信号量(WaitForSingleObjectEx):失败,访问被拒绝[部分解决]
- 断开信号失败
- Qt 绑定插槽和信号失败 QMainWindow QWebview.
- sc_start警告 W571 表示信号/端口绑定失败
- 使用std::string失败信号和槽位
- c++: assert()失败是否触发任何信号
- SIG_IGN忽略SIGINT信号失败
- 电子邮件标题显示,dkim=硬失败(测试模式)和dkim=永久错误(坏信号)
- QtSerialPort在错误的线程中实例化,导致信号/插槽失败