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

  • Home
  • SEARCH
  • 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 144491
In Process

The Archive Base Latest Questions

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

Is fprintf thread-safe? The glibc manual seems to say it is, but my application,

  • 0

Is fprintf thread-safe? The glibc manual seems to say it is, but my application, which writes to a file using single call to fprintf() seems to be intermingling partial writes from different processes.

edit: To clarify, the program in question is a lighttpd plugin, and the server is running with multiple worker threads.

Looking at the file, some of the writes are intermingled.

edit 2: It seems the problem I’m seeing might be due to lighttpd’s ‘worker threads’ actually being separate processes: http://redmine.lighttpd.net/wiki/lighttpd/Docs:MultiProcessor

Problems

By running 2 or more processes on the same socket you will have a better concurrency, but will have a few drawbacks that you have to be aware of:

  • mod_accesslog might create broken access logs, as the same file is opened twice and is NOT synchronized.
  • mod_status will have n separate counters, one set for each process.
  • mod_rrdtool will fail as it receives the same timestamp twice.
  • mod_uploadprogress will not show correct status.
  • 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. 2026-05-11T08:15:43+00:00Added an answer on May 11, 2026 at 8:15 am

    You’re confusing two concepts – writing from multiple threads and writing from multiple processes.

    Inside a process its possible to ensure that one invocation of fprintf is completed before the next is allowed access to the output buffer, but once your app pumps that output to a file you’re at the mercy of the OS. Without some kind of OS based locking mechanism you cant ensure that an entirely different application doesnt write to your log file.

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

Sidebar

Related Questions

I'm using a fprintf function to print to a new file I'm using the
I'm trying to send mail from my application server using the following code FILE
Here's the call stack from a user's crash report : Thread 0 Crashed: Dispatch
Using trylock: FILE *fp; pthread_mutex_t demoMutex; void * printHello (void* threadId) { pthread_mutex_trylock (&demoMutex);
I need to create 10 threads and print out the threadId with which thread
My intention is to transpose two files using multithreading. But the program below is
I am trying to run the following C function from Java using JNA, but
In my program fprintf() returns -1, which indicates an error. How can I find
I want to write a function which employs openMP parallelism but should work whether
I want to fprintf() 3 strings to a file, all on the same line.

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.