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.