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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:48:16+00:00 2026-06-18T18:48:16+00:00

I am writing Linux ANSI C cgi-bin server program with simultaneous access to files.

  • 0

I am writing Linux ANSI C cgi-bin server program with simultaneous access to files.

  1. Is it possible to distinguish between file existence and file locking?
    I can’t find the answer with Google.
    I’d like to write a program which tries to open file for a few seconds if fd<0
    (thinking that the file is locked for a while).
    But if the file does not exist it’s fd also <0. So the program will waste time waiting.

  2. Suppose a few threads try to append to the same file with no locking.
    One tries to add “AAAA”, another – “BBBB”.
    Can the result file be like “AABBAABB”?
    Or it will always be like AAAABBBB or BBBBAAAA?
    Or the result is unpredictable?

  • 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-18T18:48:17+00:00Added an answer on June 18, 2026 at 6:48 pm

    Am assuming IEEE Std 1003.1-2001 might defer to the ISO C standard…

    In case the fopen fails i.e. fd < 0 then the system sets some error codes…
    you can check those error codes. In case of file non-existent, the returned error would be

    ENOENT
    A component of filename does not name an existing file or filename is an empty string.

    For more reference visit:
    http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html

    For point 2: I have been doing logging of certain data in my system by more than 100 processes writing to single file simultaneously but have never seen a merger of records(file is always opened in append mode). i.e. its always like AAAABBBB

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

Sidebar

Related Questions

Newbie to C. I'm writing an ANSI C program (on Linux using gcc 4.4.6)
I'm writing a program on Linux in C to analyze core files produced from
I'm writing a program on a Linux platform that is generating text files that
I'm writing my own server in ANSI C (on Linux) and I've got one
I writing a PHP script program under Linux. In the script, I need call
I'm planning on writing a program for Linux that uses text to speech and
I'm writing a Linux program that currently compiles and works fine on x86 and
I'm writing (under linux or windows+cygwin) a java program that needs to run a
I'm writing an ANSI C app for Debian Linux, that captures data from USB
Im having trouble using my make file for a program i am writing in

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.