Advanced Programming in the UNIX Environment Hop Lee
Ch06 Process main Function Process Termination Command-Line Arguments Environment List Memory Layout Shared Libraries Memory Allocation Process Identifiers fork Function Family exit Function wait Function Family exec Function Family Process Accounting User Identification Process Times
§6.1 main Function A C program starts execution with a function called main: int main(int argc, char *argv[]); When a C program is started by the kernel, a special start-up routine is called before the main function is called. The executable program file specifies this start-up routine as the starting address for the program.
This start-up routine get the command-line arguments and the environment from the kernel and sets things up so that the main function is called.
§6.2 Process Termination There are five ways for a process to terminate: Normal termination: return from main calling exit calling _exit Abnormal termination: calling abort terminated by a signal
exit and _exit Funtions These two functions terminate a program normally: #include void exit(int status ); #include void _exit(int status ); _exit will return to the kernel immediately and exit will perform certain cleanup processing before return to the kernel.