Super User is a question and answer site for computer enthusiasts and power users. 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

What happens if there are 2 concurrent requests to create a directory in file system (what are the differences concerning this problem between knonw FSs?)? Will one request success and another fail with an error or will another request overwrite the first folder (I think by default it would be stupid. Only if I set the option for this)? Are this operations atomic?

share|improve this question

migrated from Mar 7 '13 at 9:03

This question came from our site for professional and enthusiast programmers.

Why do you think this is a "problem"? How would you have changed things so that there was no problem? – Celada Mar 7 '13 at 12:05
up vote 1 down vote accepted

One will succeed and one will fail. This is as per the manpage:

EEXIST: pathname already exists (not necessarily as a directory). This includes the case where pathname is a symbolic link, dangling or not.

Creating a directory is necessarily atomic because any other process which is examining the system at the same time will either find that the new directory exists, or that it does not. There is no such thing as a partially created directory.

You cannot set an option to make mkdir() overwrite existing directories. The behaviour stipulated by the standard when you attempt to create a directory that already exists is to fail with the error code quoted above.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .