Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7018489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:03:28+00:00 2026-05-27T23:03:28+00:00

If I call exit() implicitly: int main(){ return 0; /*exit(0) is being called */

  • 0

If I call exit() implicitly:

int main(){
  return 0; /*exit(0) is being called */
}

or explicitly:

int main(){
  exit(0);
  return 0; /* this is never reached */
}

The end-point is the same: exit() is being called. Now according to some sources, exit() will make the process do some cleanup before handing control back to the OS.

I know that eventually the kernel(the OS) is going to release all the resources. So what is so special with the process cleaning up before giving control to the kernel? What is excactly this cleanup? Why is it neccesary? How does the process know what to cleanup?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:03:29+00:00Added an answer on May 27, 2026 at 11:03 pm

    As ever, this question can be solved with reference to the C specification (N1256). 7.20.4.3 Gives this definition for exit():


    3. First, all functions registered by the atexit function are called, in the reverse order of their registration except that a function is called after any previously registered functions that had already been called at the time it was registered. If, during the call to any such function, a call to the longjmp function is made that would terminate the call to the registered function, the behavior is undefined.

    4. Next, all open streams with unwritten buffered data are flushed, all open streams are closed, and all files created by the tmpfile function are removed.

    5. Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.


    Or in English:

    First call all registered atexit functions. Next flush all unwritten buffered data. Next close open streams. Finally, return the exit status and control to the OS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I call: actor_ ! Exit How is this being converted into a construction
I'm running some code with a sys.exit() call at the end. Without the sys.exit()
When I call pthread_exit from main , the program never gets to terminate. I
I am just wondering. Do I need to call System.exit(0); right before main method
I am having a Xpage with some links. One of my link call EXIT
I call this a flash meeting, but maybe there is another more appropriate name.
I have a Main method that creates a message loop called SysTrayApp: void Main()
Is it a bad coding practice to call the exit() function in Python repeatedly?
I am trying to set the sys exit call to a variable by extern
I have a console application in C#. If something goes wrong, I call Environment.Exit()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.