CProgramHow to start:
When the kernel executes the C program (using the exec function), it calls a special startup routine before calling the main function. The executable file specifies this startup routine as the starting address of the program-this is set by the connection editor, and the connection editor is called by the C compiler. At the same time, the startup routine obtains command line parameters and environment variables from the kernel.
Process Termination
There are eight methods in total to terminate the process, of which the first five are normal, and the last three are not normal.
- Return from main. In this way, the exit function is called immediately after the main function returns.
- Call the exit function. In this method, exit first executes some cleanup operations, including calling the terminate process and closing all standard I/O streams.
- Call the _ exit or _ exit function. In this way, _ exit or _ Exit immediately enters the kernel.
- The last thread is returned from the startup routine.
- The last thread calls pthread_exit.
- Call abort.
- Receive a signal and terminate.
- The last thread responds to the cancellation request.
Termination of C program startup: