Exit () _ exit ()

Source: Internet
Author: User

FigureC program initiation and Termination

Differences:
_ Exit () function: directly stop a process, clear its memory space, and destroy various data structures in the kernel;
The exit () function is packaged based on these parameters and several processes are added before exit.

The biggest difference between the exit () function and the _ exit () functionThe exit () function checks the file opening before calling the exit system, and writes the content in the File Buffer back to the file.

# Include <unistd. h> main () {printf ("output begin \ n"); printf ("content in buffer"); // \ n cannot be added here. Once a line feed is added, then printf will immediately output, row cache mode _ exit (0);} // output: Output begin

In the standard library of Linux, there is a set of functions called "Advanced I/O". We are familiar with printf () fopen () fread () fwrite () in this column, they are also referred to as "buffer I/O (buffered I/O)", which is characterized by a buffer in the memory corresponding to each opened file. Each time a file is read, several more records will be read, so that the next time you read the file, you can directly read it from the memory buffer. Each time you write the file, it is only written into the buffer zone in the memory, when a certain number of conditions are met (or a specific character, such as the line break \ n and the end EOF file), the buffer content is written to the file at one time, this greatly increases the speed of reading and writing files, but it also brings us a little trouble in programming. If there is some data, we think that the file has been written, because it does not meet the specific conditions, they are only saved in the buffer, then we use _ exit () if a function is used to directly shut down the process, data in the buffer will be lost. If you want to ensure data integrity, you must use the exit () function.

Before terminating the process that calls exit (), perform the following steps:
1. Cleanup ();
2. Functions registered in atexit;
Finally, call the _ exit () function...

_ Exit () does not execute the I/O cache refresh action

_ Exit ends the calling process, but does not close the file (the file should also be closed), does not clear the output cache, and does not call the exit function.
The exit function terminates the calling process. Before exiting the program, all files are closed and the output content is buffered.
The definition will be refreshed and All refreshed "export functions" will be called (defined by atexit ).

_ Exit will also close the file.
_ Exit ):
1, any open file descriptors belonging to the process are closed
2, any children of the process are inherited by process 1, init
3, the process's parent is sent a sigchld Signal

After the cleaning is completed, call _ exit to terminate the process.

 

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.