Sun Microsystems, Inc.
spacerspacer
spacer   www.sun.com docs.sun.com | | |  
spacer
black dot
   
A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z
    
 
System Callsexit(2)


NAME

 exit, _exit - terminate process

SYNOPSIS

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

DESCRIPTION

 

The exit() function first calls all functions registered by atexit(3C), in the reverse order of their registration. Each function is called as many times as it was registered.

If a function registered by a call to atexit(3C) fails to return, the remaining registered functions are not called and the rest of the exit() processing is not completed. If exit() is called more than once, the effects are undefined.

The exit() function then flushes all output streams, closes all open streams, and removes all files created by tmpfile(3C).

The _exit() and exit() functions terminate the calling process with the following consequences:

  • All of the file descriptors, directory streams, conversion descriptors and message catalogue descriptors open in the calling process are closed.
  • If the parent process of the calling process is executing a wait(2), wait3(3C), waitid(2) or waitpid(2), and has neither set its SA_NOCLDWAIT flag nor set SIGCHLD to SIG_IGN, it is notified of the calling process's termination and the low-order eight bits (that is, bits 0377) of status are made available to it. If the parent is not waiting, the child's status will be made available to it when the parent subsequently executes wait(2), wait3(3C), waitid(2) or waitpid(2).
  • If the parent process of the calling process is not executing a wait(2), wait3(3C), waitid(2) or waitpid(2), and has not set its SA_NOCLDWAIT flag, or set SIGCHLD to SIG_IGN, the calling process is transformed into a zombie process. A zombie process is an inactive process and it will be deleted at some later time when its parent process executes wait(2), wait3(3C), waitid(2) or waitpid(2). A zombie process only occupies a slot in the process table; it has no other space allocated either in user or kernel space. The process table slot that it occupies is partially overlaid with time accounting information (see <sys/proc.h>) to be used by the times(2) function.
  • Termination of a process does not directly terminate its children. The sending of a SIGHUP signal as described below indirectly terminates children in some circumstances.
  • A SIGCHLD will be sent to the parent process.
  • The parent process ID of all of the calling process's existing child processes and zombie processes is set to 1. That is, these processes are inherited by the initialization process (see intro(2)).
  • Each mapped memory object is unmapped.
  • Each attached shared-memory segment is detached and the value of shm_nattch (see shmget(2)) in the data structure associated with its shared memory ID is decremented by 1.
  • For each semaphore for which the calling process has set a semadj value (see semop(2)), that value is added to the semval of the specified semaphore.
  • If the process is a controlling process, the SIGHUP signal will be sent to each process in the foreground process group of the controlling terminal belonging to the calling process.
  • If the process is a controlling process, the controlling terminal associated with the session is disassociated from the 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 the newly-orphaned process group.
  • If the parent process has set its SA_NOCLDWAIT flag, or set SIGCHLD to SIG_IGN, the status will be discarded, and the lifetime of the calling process will end immediately.
  • If the process has process, text or data locks, an UNLOCK is performed (see plock(3C) and memcntl(2)).
  • All open named semaphores in the process are closed as if by appropriate calls to sem_close(3RT). All open message queues in the process are closed as if by appropriate calls to mq_close(3RT). Any outstanding asynchronous I/O operations may be cancelled.
  • An accounting record is written on the accounting file if the system's accounting routine is enabled (see acct(2)).
  • An extended accounting record is written to the extended process accounting file if the system's extended process accounting facility is enabled (see acctadm(1M)).
  • If the current process is the last process within its task and if the system's extended task accounting facility is enabled (see acctadm(1M)), an extended accounting record is written to the extended task accounting file.

RETURN VALUES

 

These functions do not return.

ERRORS

 

No errors are defined.

USAGE

 

Normally applications should use exit() rather than _exit().

ATTRIBUTES

 

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPEATTRIBUTE VALUE
MT-Level_exit is Async-Signal Safe

SEE ALSO

 

acctadm(1M), intro(2), acct(2), close(2), memcntl(2), semop(2), shmget(2), sigaction (2), times(2), wait(2), waitid(2), waitpid(2), atexit(3C), fclose(3C), mq_close(3RT), plock(3C), signal(3HEAD), tmpfile(3C), wait3(3C), attributes(5)


SunOS 5.9Go To TopLast Changed 10 Dec 1999

 
      
      
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.