Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

O_EXLOCK vs flock()

What is the difference between calling open() with the O_EXLOCK flag versus calling just calling open() and then calling flock()? The latter has a potential race condition, but other than that both ways gets an exclusive process lock on a file, right?


1 Answers

The only difference is atomicity: open() with O_EXLOCK is atomic, whereas open() followed by flock() are two distinct operations.

like image 183
NPE Avatar answered Nov 21 '25 15:11

NPE