atexit函数

atexit函数

函数名: atexit 
头文件:#include

#include<stdio.h>
#include<stdlib.h>

void fun1()
{
    printf("fun1():");
}
void fun2()
{
    printf("fun2():");
}
void fun3()
{
    printf("fun3():");
}
void fun4()
{
    printf("fun4():");
}
void fun5()
{
    printf("fun5():");
}
int main()
{
    atexit(fun1);
    atexit(fun2);
    atexit(fun2);
    atexit(fun3);
    atexit(fun4);
    atexit(fun5);
    exit(0);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

这里写图片描述

可以看出,exit在这里调用了5个函数,并且这些注册函数的顺序与它们登记时候的顺序相反。同一个函数如若登记多次,则也会被调用多次。 
进程的终止方式: 
有8种方式使进程终止,其中前5种为正常终止,它们是 
1:从 main 返回 
2:调用 exit 
3:调用 _exit 或 _Exit //不会调用终止程序 
4:最后一个线程从其启动例程返回 
5:最后一个线程调用pthread_exit 
异常终止有3种,它们是 //异常终止也不会调用终止程序 
6:调用 abort 
7:接到一个信号并终止 
8:最后一个线程对取消请求做出响应


猜你喜欢

转载自blog.csdn.net/coolwriter/article/details/80208550