确定我的应用程序是否因调用 _exit() 而终止

Determine if my application terminated due to a call to _exit()

我可以通过使用 atexit 或析构函数来确定我的应用程序是否因调用 exit() 而终止。有什么方法可以确定我的应用程序上次是否因 _exit()?

而终止

来自man page

The function _exit() terminates the calling process "immediately". Any open file descriptors belonging to the process are closed; any children of the process are inherited by process 1, init, and the process's parent is sent a SIGCHLD signal.

The value status is returned to the parent process as the process's exit status, and can be collected using one of the wait(2) family of calls.

而且您不能期望 atexit() 被调用。但是,与 exit 类似,设置状态并从 _exit 返回,例如,您可能希望从调用脚本进行测试。 (例如 exit(0);_exit(1);,如果返回值为 1,则您知道使用了 _exit,而不是 exit。)