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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:00:59+00:00 2026-06-16T22:00:59+00:00

I wrote a small program in C FILE *fp = fopen(/tmp/file, w+); char *buf

  • 0

I wrote a small program in C

FILE *fp = fopen("/tmp/file", "w+");
char *buf = "hello";
fwrite(buf, 1, strlen(buf), fp);
for(;;);

On a shell I use cat to read the contents, the file is empty as fflush is not being called. My question is will it remain like this forever or will at sometime the data will be pushed to disk?

In other words, does the fwrite call crosses the File systems boundary to the VM subsystem, if yes then page daemon should at sometime be invoked which will flush the contents to the file. If not then the data will remain there forever till the file is closed or flushed.

  • 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-06-16T22:01:00+00:00Added an answer on June 16, 2026 at 10:01 pm

    Each stdio FILE has an internal buffer (see setvbuf for more). The fwrite or fprintf or fputs calls are filling that buffer. It will be written to the file system (using the write(2) syscall, executed inside the kernel) only when full or when you call fflush.

    You may have line-buffering (e.g. for stdout), then the write is triggered when a newline appears in the buffer

    P.S. try to strace your program to understand what it is doing.

    P.P.S Linux is free software: you could study the source code of the GNU libc or of musl-libc -whose source I find easier to read.

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

Sidebar

Related Questions

I wrote this small C++ program and built it(Release) #include<iostream> int main(){ std::cout<<Hello World;
I wrote a small program in C where I opened a file successfuly, then
I wrote a small program to simply load a Wavefront OBJ mesh file and
I have a small example program which simply fopen s a file and uses
I wrote this small C program: #include <stdio.h> #include <stdlib.h> int main() { FILE
I wrote a small Hello, World! program in C and here it is: #include
I wrote a small program, that creates files at an interval of 1 minute.
I wrote a small program to test accessing a widget parent's slot. Basically, it
I wrote a small test program for flipperview. I have 3 views. I call
So I wrote a project-management program for a small business using Microsoft Access 2007.

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.