How C Programs are started and terminated

Source: Internet
Author: User

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.

    1. Return from main. In this way, the exit function is called immediately after the main function returns.
    2. 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.
    3. Call the _ exit or _ exit function. In this way, _ exit or _ Exit immediately enters the kernel.
    4. The last thread is returned from the startup routine.
    5. The last thread calls pthread_exit.
    6. Call abort.
    7. Receive a signal and terminate.
    8. The last thread responds to the cancellation request.
Termination of C program startup:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.