exit, _exit

Very Important Picture

Function Prototype

#include <stdlib.h>
void exit(int status)
#include <unistd.h>
void _exit(int status)

exit

呼叫 exit 後會執行這些步驟

  • call exit handlers (用 atexit 註冊)
  • close all file descriptors
  • flush I/O streams
  • put the process into “zombie” status (後面會講)

_exit

exit 如果是安分守己的員工,會在工作完後將整理桌子、保存文件後才下班,那 _exit 就是時間到了就閃人,啥也不管的人,他會直接將 process 變成 zombie status,stream 中還沒有 synchronize 的資訊會直接消失

常和 vfork 一起用