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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:42:59+00:00 2026-05-11T05:42:59+00:00

I opened a file stream to a very big file using fopen. Before performing

  • 0

I opened a file stream to a very big file using fopen. Before performing any read operation on that stream, I deleted the file using unlink(). And still, I was able to read the whole file.

I am guessing that there is a buffer associated with the stream, which holds the data of the file. But obviously that buffer will have a limit. That was the reason why I chose a_big_file whose size was 551126688 bytes or 526MB.

I want to know what is the exact reason behind it. Here is the test code that I used.

#include <stdio.h> #include <unistd.h>  int main(){      FILE *fp;     long long int file_size = 0;     int bytes_read = 0;     char buf[1];      fp = fopen('a_big_file', 'r');      unlink('a_big_file');      while(0 != (bytes_read = fread(buf, 1, 1, fp))){         file_size += bytes_read;     }      printf('file_size is %llu\n', file_size);      return 0; } 

Output: file_size is 551126688

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:42:59+00:00Added an answer on May 11, 2026 at 5:42 am

    In Unix and Unix-like operating systems, the file doesn’t actually go away until the last open file handle on it is closed. This is a very useful trick for temporary files – if you unlink it as soon as you open it, the file won’t be visible to other processes, and it will be removed from the system as soon as your program closes it, ends or crashes. That helps prevent the proliferation of orphan temp files.

    Practically (glossing over some technical details here) what happens is that Unix file systems are reference counted. When you open the file, you actually get connected to the file’s inode (which is the real indication of where the actual content of the file lives). But unlinking the file just removes the directory entry, so the file doesn’t have a name any more. The file system will only reclaim the file space (ie the inode) if it isn’t in any directory entries, AND nobody has it open. The other processes can’t open it in the ordinary manner because they can’t map a file name to the inode.

    Note that Unix file systems allow multiple directory entries to point to the same inode – we call that a ‘hard link’. If you do a ‘ls -l’, one of the fields is the count of hard links to that same inode, and if you do an ‘ls -li’, you can see the actual inode address.

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

Sidebar

Related Questions

I'm using the PHP Eclipse. When a XML file is opened, Eclipse doesn't seem
What translation occurs when writing to a file that was opened in text mode
In C#/.NET (on Windows) is there a way to read a growing file using
I would like to open a file using open file dialog. If the opened
Is there any way to access the file descriptor of a file opened in
I'm looking to call a subprocess with a file descriptor opened to a given
How can I find out the size of a file I opened with an
Is there a way to check if a file has been opened by ReWrite
When sockets are created or files are opened/created in C, is the file descriptor
I've opened an old workspace that is a library and its test harness. It

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.