Chinaunix首页 | 论坛 | 博客
  • 博客访问: 177661
  • 博文数量: 42
  • 博客积分: 2185
  • 博客等级: 大尉
  • 技术积分: 455
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-11 21:32
文章分类

全部博文(42)

文章存档

2012年(5)

2011年(13)

2010年(6)

2009年(18)

我的朋友

分类: C/C++

2009-11-27 17:50:25

            Behaviour of atexit under Linux

1. use atexit() in a single process

  当程序正常exit时,调用次序与atexit()注册的次序相反,即:最后注册的atexit() entry,最先被调用。fork()时,子进程会继承父进程已经注册的atexit() entry。

2. use atexit() in thread

  在线程中调用atexit()是,遵循同样原则,即不论线程进程调用atexit(),推出的时候按照相反的路径执行atexit entry。与进程推出的次序无关。

3. use atexit() in so (dynamic libraries)
  在so中亦可使用atexit(),原则同上;但当so被映射时(通过dlopen/dlsym),so不能再被dlclose()反映射,否则会导致segfault。注册的atexit() entry将会在映射该so的进程终止时按照1, 2的原则调用。(注意,不能保证别的Unix环境下行为完全一致)

P.S: atexit()注册的例程必须在进程被exit(非_exit)终止时才会执行。

please see ``man atexit'' for more details.

阅读(1178) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~