进程退出方式:
1.正常结束:
1)main 函数结束;
2)exit(3) 结束:调用atexit (3) , on_exit (3) 函数.
All open stdio(3) streams are flushed and closed. Files created by tmpfile(3) are removed.
3)_exit(2) 结束:不会调用atexit on_exit函数
The function _exit() terminates the calling process "immediately". Any open file descriptors belong‐
ing 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.
2.非正常结束:
1)信号结束:
2)abort函数:实际上也是给发送一个SIGABRT信号.
atexit函数的测试代码:
#include <iostream>
#include <stdlib.h>
using namespace std;
void atexit1()
{
cout << "in 1" << endl;
}
void atexit2()
{
cout << "in 2" << endl;
}
int main()
{
atexit(atexit1);
atexit(atexit2);
cout << "before end" << endl;
return -1;
}
./testretvalbefore end
in 2
in 1