可以退出()不能终止进程? [英] Can exit() fail to terminate process?

查看:96
本文介绍了可以退出()不能终止进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册在我的程序的信号处理程序。在接收到干扰信号(SIGABRT),我称之为出口(-1)'的信号处理程序退出的过程。但在少数ocassions因为注意到了,它调用exit(),但不能终止进程。

I have a registered a signal handler in my program. Upon receiving an undesired signal (SIGABRT), i call 'exit(-1)' in signal handler to exit the process. But as noticed on few ocassions, it calls exit() but fails to terminate the process.

是随机生成的问题,我在退出执行强烈怀疑()。

The issue was randomly generated and I strongly suspect on execution of exit().

难道还有其中的exit()可能无法终止该进程的任何原因或情况。

Can there be any reasons or cases in which the exit() can fail to terminate the process.

感谢。

推荐答案

你叫退出()从信号处理程序?

人7信号部分的异步信号安全功能您可以看到所有保证的功能从调用时工作信号处理程序:

In man 7 signal, section Async-signal-safe functions you can see all the functions that are guaranteed to work when called from an signal handler:

一个信号处理函数必须非常小心,因为其他地方的处理可被中断
         在程序的执行某些任意点。 POSIX有安全功能的概念。如果
         信号中断不安全功能的执行,并且处理程序调用一个不安全的功能,然后
         该程序的行为是不确定的。

A signal handler function must be very careful, since processing elsewhere may be interrupted at some arbitrary point in the execution of the program. POSIX has the concept of "safe function". If a signal interrupts the execution of an unsafe function, and handler calls an unsafe function, then the behavior of the program is undefined.

POSIX.1-2004(也称为POSIX.1-2001技术勘误2)需要一个实现
         保证以下功能可以安全地被称为一个讯号处理器中:

POSIX.1-2004 (also known as POSIX.1-2001 Technical Corrigendum 2) requires an implementation to guarantee that the following functions can be safely called inside a signal handler:

有你可以看到函数 _Exit() _exit()中止( ),但值得注意的是不是退出()。所以,你不应该从信号处理程序中调用它。

There you can see functions _Exit(), _exit() and abort(), but notably not exit(). So you should not call it from a signal handler.

讨厌的事情是,即使你从信号处理程序调用不安全功能(的printf()的?),它只是工作的大部分时间...但并非总是如此。

The nasty thing is that even if you call an unsafe function from a signal handler (printf() any?) it will just work most of the time... but not always.

这篇关于可以退出()不能终止进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆