Return N and exit (int n) Summary

Source: Internet
Author: User

Exit (int n) is actually a direct exitProgramBecause the default standard program entry is
Int main (INT argc, char ** argv), the return value is int type.
Generally, run a program under the shell and run the echo $? Command? You can get the return value of the program, that is, the exit value. In Main (), you can use return N or exit (n) directly. By default, Unix returns 0 if it exits correctly, and non-0 if it returns an error.

 

Theoretically, exit (int n) can return any int INTEGER (<255 ). Different values returned are mainly processed by the caller.
A separate process is returned to the operating system. If it is a multi-process, it is returned to the parent process.
Call functions such as waitpid () in the parent process to obtain the exit status of the child process for different processing.

 

Exit (0) indicates that the program is normal, exit (1)/exit (-1) indicates that the program exits abnormally.
Exit () ends the current process/current program/. In the whole program, it ends when exit is called.
Exit (1) indicates that the process Exits normally. 1 is returned;
Exit (0) indicates that the process exits abnormally. 0 is returned.

Return () is the return of the current function. Of course, if it is in the main function, the current process is naturally ended. If it is not, it is returned to the previous layer for calling. If you want to check whether the process Exits normally in multiple processes, you need to use the return value of the previous process ..
Return is only the return of the function. It will be executed later.

 

there are two types of program c termination: normal termination and exceptional termination.
normal termination can be divided into return, exit, _ exit, _ exit, pthreade_exit
exception middle finger: abort, signal, thread response cancellation
mainly refers to the first four types of normal termination, namely, exit functions.
# include /* Iso c */
void exit (INT status);
void _ exit (INT status);
# include /* POSIX */
void _ exit (INT status);
the difference between the above three functions is:
exit () (or return 0) it will call the standard I/O cleanup programs (such as fclose) that terminate the processing program and the user space, and _ exit will be directly taken over by the kernel for cleanup without calling.
therefore, exit (0) in the main function is equivalent to return 0.

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.