linux process退出方式

来源:互联网 发布:小满软件 垃圾 编辑:程序博客网 时间:2024/06/05 16:54

在linux系统里,进程退出通常有5种常见的方式:

  • 直接执行return语句,比如在main函数里,直接用return退出,这与调用exit方法是等价的
  • 直接调用exit,这是ISO C里定义的,包含所有的exit handlers,这些handlers是由atexit注册过的;关掉所有的standard I/O streams
  • 调用_exit或_Exit方法,在ISO C里,_Exit结束进程时并不执行exit handlers或signal handlers. 而在UNIX系统里,_Exit和_exit是同步的,并不会flush standard I/O stream.
  • Executing a return from the start routine of the last thread in the process. The
    return value of the thread is not used as the return value of the process,
    however. When the last thread returns from its start routine, the process exits
    with a termination status of 0.
    进程中的线程里执行return
  • 调用pthread_exit,这个通常在线程中使用

不常见的3种方式

  • 调用abort方法,会产生一个SIGABRT的signal
  • 进程收到特定的signals
  • 前一个线程回复一个cancellation request