该signal()函数是否会覆盖进程可能已设置的其他信号调用?即如果SIGINT处理程序已由进程设置,并且DLL调用signal(SIGINT,xxx)以处理其自己的终止代码,原始SIGINT处理程序是否会被禁用?
该signal()呼叫:
将调用新的处理程序而不是旧的处理程序.如果你想链接它们,你需要做类似的事情:
typedef void (*Handler)(int signum);
static Handler old_int_handler = SIG_IGN;
static void int_handler(int signum) /* New signal handler */
{
/* ...do your signal handling... */
if (old_int_handler != SIG_IGN && old_int_handler != SIG_DFL)
(*old_int_handler)(signum);
}
static void set_int_handler(void) /* Install new handler */
{
Handler old = signal(SIGINT, SIG_IGN);
if (old != SIG_IGN)
{
old_int_handler = old;
signal(SIGINT, int_handler);
}
}
static void rst_int_handler(void) /* Restore original handler */
{
Handler old = signal(SIGINT, SIG_IGN);
if (old == int_handler)
{
signal(SIGINT, old_int_handler);
old_int_handler = SIG_IGN;
}
}
void another_function()
{
/* ... */
set_int_handler();
/* ... */
rst_int_handler();
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
如果忽略中断,则会忽略它们.如果用户定义的中断处理程序正在处理中断,则会调用您的信号处理代码和原始信号处理代码.
请注意,建议从Christian.K约在DLL(共享库)不处理信号也是相关的和有效的.上面的描述假设您决定忽略该建议.
| 归档时间: |
|
| 查看次数: |
2566 次 |
| 最近记录: |