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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:02:51+00:00 2026-05-27T14:02:51+00:00

Suppose I have a process call A which call fopen(filename,w); every second, and write

  • 0

Suppose I have a process call A which call fopen(filename,”w”); every second, and write data in it, while process B call fopen(filename,”r”) every 0.2 second and read data from it !!

In a very seldom situation, while A is writing data , before A fclose it, B process do fopen and read data from it. I think it has a sync problem!

Using Mutex is easy in thread, but I haven’t tried mutex between processes. The data is only 400 bytes at most, I’d like to know what is the easy way to avoid a process writing data, and another process reading at the same time, or, while one process A fopen a file, another process B would wait until the process A fclose the file!

  • 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-27T14:02:52+00:00Added an answer on May 27, 2026 at 2:02 pm

    If you must use files (as @aix has said, there may be better ways), don’t try to read files as they are being written or the results will be undefined.

    Instead, write the data to a different filename, close it, and then move it to the right place (on Linux, use rename()).

    If you don’t like that, try using file locks. On Linux, at least, these don’t actually prevent access to the file, they just act as inter-process mutexes. You don’t say what OS you have, but for Linux, see man 2 flock.

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

Sidebar

Related Questions

Suppose I have a process which spawns exactly one child process. Now when the
Let's suppose that I have 2 processes in Erlang, and each process has a
Suppose I have a simple program which takes argument input in one of the
Suppose I have a java program, myProgram.jar , which I have running on a
I have a process, let's call it Process A, that is hosting a simple
Suppose I have this shell script call cpdir: (cd $1 ; tar -cf -
I have a high-priority process that needs to pass data to a low-priority process.
I have a dialog based MFC application through which I have to call a
Suppose I want to call a subprocess from within my program, and I want
Here is the scenario: I have a java main process, which uses JMS to

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.