exit 中文man页面

系统
函数 exit() 使得程序正常中止,status & 0377 的值被返回给父进程 (参见 wait(2)) 。所有用 atexit() 和 on_exit() 注册的函数都以与注册时相反的顺序被依次执行。使用 tmpfile() 创建的文件被删除。

NAME

exit - 使程序正常中止  

SYNOPSIS 总览

#include <stdlib.h>

void exit(int status);

DESCRIPTION 描述

函数 exit() 使得程序正常中止,status & 0377 的值被返回给父进程 (参见 wait(2)) 。所有用 atexit()on_exit() 注册的函数都以与注册时相反的顺序被依次执行。使用 tmpfile() 创建的文件被删除。

C 标准定义了两个值 EXIT_SUCCESSEXIT_FAILURE,可以作为 exit() 的参数,来分别指示是否为成功退出。  

RETURN VALUE 返回值

函数 exit() 不会返回。  

CONFORMING TO 标准参考

SVID 3, POSIX, BSD 4.3, ISO 9899 (``ANSI C'')  

NOTES 要点

在 exit 处理过程中,可能会使用 atexit()on_exit() 注册其他的函数。通常,***注册的函数被从已注册函数链中摘下来,然后执行。如果在处理过程中,又调用了 exit()longjmp(),那么发生的行为是未定义的。

相对于使用 0 和非零值 1 或 -1,使用 EXIT_SUCCESS 和 EXIT_FAILURE 可以稍微增加一些可移植性 (对非 Unix 环境)。特别的,VMS 使用一种不同的约定。

BSD 试图标准化退出代码 - 参见文件 <sysexits.h>

exit() 之后,退出状态必须传递给父进程。这里有三种情况。如果父进程已设置了 SA_NOCLDWAIT,或者已将 SIGCHLD 的处理句柄设置成了 SIG_IGN,这个状态将被忽略。这时要退出的进程立即消亡。如果父进程没有表示它对退出状态不感兴趣,仅仅是不再等待,那么要退出的程序变成一个僵尸进程 (``zombie'',除了包含一个字节的退出状态外,什么也不是)。这样在父进程后来调用 wait() 函数族之一时,可以得到退出状态。

如果所用实现支持 SIGCHLD 信号,信号将被发送到父进程。如果父进程已设置了 SA_NOCLDWAIT,它被取消定义。(?)

如果进程是一个 session leader,它的控制终端是会话的控制终端,那么这个终端的前台进程组的每个进程都将收到 SIGHUP 信号;终端将与这个会话断开,可以再被一个新的控制进程获得。

如果进程的退出使得一个进程组成为孤儿,并且这个新近成为孤儿的进程组中任何的进程被中止,进程组中所有的进程将依次收到 SIGHUP 和 SIGCONT 信号。  

SEE ALSO 参见

_exit(2), wait(2), atexit(3), on_exit(3), tmpfile(3)

#p#

NAME

exit - cause normal program termination  

SYNOPSIS

#include <stdlib.h>

void exit(int status);

DESCRIPTION

The exit() function causes normal program termination and the the value of status & 0377 is returned to the parent (see wait(2)). All functions registered with atexit() and on_exit() are called in the reverse order of their registration, and all open streams are flushed and closed. Files created by tmpfile() are removed.

The C standard specifies two defines EXIT_SUCCESS and EXIT_FAILURE that may be passed to exit() to indicate successful or unsuccessful termination, respectively.  

RETURN VALUE

The exit() function does not return.  

CONFORMING TO

SVID 3, POSIX, BSD 4.3, ISO 9899 (``ANSI C'')  

NOTES

During the exit processing, it is possible to register additional functions with atexit() and on_exit(). Always the last-registered function is removed from the chain of registered functions, and invoked. It is undefined what happens if during this processing either exit() or longjmp() is called.

The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to non-Unix environments) than that of 0 and some nonzero value like 1 or -1. In particular, VMS uses a different convention.

BSD has attempted to standardize exit codes - see the file <sysexits.h>.

After exit(), the exit status must be transmitted to the parent process. There are three cases. If the parent has set SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the status is discarded. If the parent was waiting on the child it is notified of the exit status. In both cases the exiting process dies immediately. If the parent has not indicated that it is not interested in the exit status, but is not waiting, the exiting process turns into a "zombie" process (which is nothing but a container for the single byte representing the exit status) so that the parent can learn the exit status when it later calls one of the wait() functions.

If the implementation supports the SIGCHLD signal, this signal is sent to the parent. If the parent has set SA_NOCLDWAIT, it is undefined whether a SIGCHLD signal is sent.

If the process is a session leader and its controlling terminal the controlling terminal of the session, then each process in the foreground process group of this controlling terminal is sent a SIGHUP signal, and the terminal is disassociated from this session, allowing it to be acquired by a new controlling process.

If the exit of the process causes a process group to become orphaned, and if any member of the newly-orphaned process group is stopped, then a SIGHUP signal followed by a SIGCONT signal will be sent to each process in this process group.  

SEE ALSO

_exit(2), wait(2), atexit(3), on_exit(3), tmpfile(3)

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-25 15:09:38

clearerr中文man

2011-08-25 15:19:39

dirname中文man

2011-08-25 15:21:53

execl中文man

2011-08-25 16:28:50

fread中文man

2011-08-25 16:52:54

getchar中文man

2011-08-25 17:27:58

rewind中文man

2011-08-25 18:41:31

vprintf中文man

2011-08-23 10:03:40

useradd中文man

2011-08-23 10:29:02

chpasswd中文man

2011-08-23 10:34:22

convertquot中文man

2011-08-23 15:39:34

rpmbuild中文man

2011-08-23 18:00:21

LDP中文man

2011-08-25 09:40:49

UPDATE中文man

2011-08-24 15:11:15

explain中文man

2011-08-24 15:29:06

grant中文man

2011-08-24 15:48:38

INSERT中文man
点赞
收藏

51CTO技术栈公众号