Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

So how does exit() work?

Tags:

c

exit

If I use exit(), GCC doesn't give a warning:

int main()
{
    exit(EXIT_SUCCESS);
}

If we use any other function, we will definitely meet such a warning:

warning: control reaches end of non-void function

How does exit() make the parent function get its return value without using return(), which the compiler makes?

like image 214
compile-fan Avatar asked May 28 '11 23:05

compile-fan


People also ask

How does exit () work?

C library function - exit() The C library function void exit(int status) terminates the calling process immediately. Any open file descriptors belonging to the process are closed and any children of the process are inherited by process 1, init, and the process parent is sent a SIGCHLD signal.

How does exit () work in Python?

_exit() method in Python is used to exit the process with specified status without calling cleanup handlers, flushing stdio buffers, etc. Note: This method is normally used in the child process after os. fork() system call. The standard way to exit the process is sys.

What does exit 1 do in Python?

exit(1) means there was some issue / error / problem and that is why the program is exiting. This is not Python specific and is pretty common. A non-zero exit code is treated as an abnormal exit, and at times, the error code indicates what the problem was. A zero error code means a successful exit.


1 Answers

On GNU libc, exit is declared with __attribute__((__noreturn__)), which tells gcc that the function does not return.

like image 138
Chris Jester-Young Avatar answered Oct 09 '22 22:10

Chris Jester-Young