首页  

exit atexit 及 abort     所属分类 c 浏览量 604
exit 正常终止  abort 异常终止
Before termination, exit() performs the following functions in the order listed:
1. Call the functions registered with the atexit function, in the reverse order of their registration.
2. Flush all open output streams.
3. Close all open streams.
4. Unlink all files created with the tmpfile function.
           
The abort() function causes abnormal program termination to occur, unless the signal SIGABRT is being caught and the signal handler does not return.
Any open streams are flushed and closed.

abort 不会调用 atexit 注册的函数


#include "stdio.h" #include "stdlib.h" void func1(){ printf("func1 before exit \n"); } void func2(){ printf("func2 before exit \n"); } int main(){ int input; scanf("%d", &input); atexit(func1); atexit(func2); printf("input=%d\n",input); switch(input){ case 0: printf("正常退出\n"); exit(EXIT_SUCCESS); break; case 1: printf("异常终止\n"); abort(); break; case 2: { char *path = getenv("PATH"); printf("PATH=%s\n", path); break; } case 3: system("pwd"); break; case 4: printf("exit with return code 4\n"); exit(4); break; default: break; } printf("done\n"); return 0; }

上一篇     下一篇
C语言排序和搜索

C语言 rand srand rand_r

C语言动态内存分配与释放

C语言stdlib使用实例

程序各个段text data bss stack heap

C++左值和右值