5

What are the differences between void quick_exit( int exit_code ) which was included in c11 standard and void exit( int exit_code ) function that already existed before c11 standard?

coder
  • 12,832
  • 5
  • 39
  • 53
  • `quick_exit` doesn't call handlers registered with `atexit`. – Daniel Kamil Kozar Sep 16 '16 at 18:12
  • I don't know enough to mark this as duplicate but have you [read this](http://stackoverflow.com/questions/9758495/what-is-the-difference-between-stdquick-exit-and-stdabort-and-why-was-stdq)? How much research have you really done? – Weather Vane Sep 16 '16 at 18:13
  • @Weather Vane ,no it wasn't so easy to find so thanks very much, it has a lot info!! ,I googled it but i didn't clearly understand when use the one function and when the other, also i wasn't searching that much for c11 standard so it didn't happen to find the post you recommended. – coder Sep 16 '16 at 18:15
  • I also [found this PDQ](https://msdn.microsoft.com/en-us/library/mt633793.aspx) – Weather Vane Sep 16 '16 at 18:16
  • This doesn't have any information about where these function differ ,do they have some important difference or they are pretty much the same, if they are the same why was needed to declare a new exit function?? – coder Sep 16 '16 at 18:20
  • 2
    It's worth mentioning that `quick_exit` is still unimplemented on macOS as of today (year 2023). – aafulei Apr 27 '23 at 07:20

3 Answers3

6

exit ensures that stream buffers are flushed, closed, etc. Such behavior for quick_exit is not specified by the standard.

With these you can define two ways of quitting an application, one that lets you terminates with full cleaning (made by functions registered with atexit), and the other to let applications terminate more quickly without cleaning too much things (calls to functions registered with at_quick_exit).

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
5

Only the functions _Exit, abort, signal, and quick_exit may be called in the signal handler from the header signal.h.

Calling any other function like, exit, will cause undefined behavior.

2501
  • 25,460
  • 4
  • 47
  • 87
4

The Linux manual page for quick_exit is summarized as follows:

quick_exit - exits a program quickly, running minimal cleanup

The quick_exit() function exits the program quickly, calling any cleanup functions registered with at_quick_exit(3), but not with atexit(3).

And for exit:

exit - cause normal process termination

The exit() function causes normal process termination and the value of status & 0377 is returned to the parent (see wait(2)).

So the main difference is that quick_exit does not perform as many cleanup operations upon exiting.