Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am implementing a server in C for a course project. The server should serve more than one client simultaneously. The description of the project states that fork() should be used to serve more than one client. Each children should write something to a common file. How do I handle this synchronously? Is there any mechanism like in Java where only one thread can use a function at the same time?

share|improve this question
Have a look at, say, logging in Apache. – reinierpost May 25 '12 at 12:49
up vote 3 down vote accepted

Because you're using fork(), you are spawning new processes, not new threads. That means you can't synchronize via monitors. You can, however, synchronize via named semaphores.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.