Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Mar 7 '13 at 9:03

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

1  
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

1 Answer 1

up vote 0 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

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.