Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.