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 6556253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:55:16+00:00 2026-05-25T12:55:16+00:00

Question: What happens if I exit program without closing files? Are there some bad

  • 0

Question:

What happens if I exit program without closing files?

Are there some bad things happening (e.g. some OS level file descriptor array is not freed up..?)

And to the answer the same in both cases

  • programmed exiting
  • unexpected crash

Code examples:

With programmed exiting I mean something like this:

int main(){
    fopen("foo.txt","r");
    exit(1);
}

With unexpected crash I mean something like this:

int main(){
    int * ptr=NULL;
    fopen("foo.txt","r");
    ptr[0]=0;  // causes segmentation fault to occur
}

P.S.

If the answer is programming language dependent then I would like to know about C and C++.

If the answer is OS dependent then I am interested in Linux and Windows behaviour.

  • 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-25T12:55:17+00:00Added an answer on May 25, 2026 at 12:55 pm

    It depends on how you exit. Under controlled circumstances (via exit() or a return from main()), the data in the (output) buffers will be flushed and the files closed in an orderly manner. Other resources that the process had will also be released.

    If your program crashes out of control, or if it calls one of the alternative _exit() or _Exit() functions, then the system will still clean up (close) open file descriptors and release other resources, but the buffers won’t be flushed, etc.

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

Sidebar

Related Questions

Actual question(s): What happens in Windows when a program crashes from an uncaught exception?
Does anyone know? And a bigger question is what happens when you encounter this
Question in the title. And what happens when all 3 of $_GET[foo] , $_POST[foo]
This is just a quick question to understand correctly what happens when you create
Title is the entire question. Can someone give me a reason why this happens?
Java 6 API question. Does calling LockSupport.unpark(thread) have a happens-before relationship to the return
This questions is related to java exceptions, why are there some cases that when
I had a program developed in Python (2.7 & 3.2) that reads three files
I have some question. I have the html form with one hidden input element.
I have a question What happend when I declare a variable inside a method,

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.