Skip to main content
Tweeted twitter.com/StackUnix/status/1184484305122279425
deleted 30 characters in body
Source Link
Tim
  • 106.8k
  • 234
  • 650
  • 1.1k

https://unix.stackexchange.com/a/12818/674 says

Lock files are used by programs to ensure two (well-behaved) separate instances of a program, which may be running concurrently on one system, don't access something else at the same time. The idea is before the program accesses its resource, it checks for presence of a lock file, and if the lock file exists, either error out or wait for it to go away. When it doesn't exist, the program wanting to "acquire" the resource creates the file, and then other instances that might come across later will wait for this process to be done with it. Of course, this assumes the program "acquiring" the lock does in fact release it and doesn't forget to delete the lock file.

This works because the filesystem under all UNIX-like operating systems enforces serialization, which means only one change to the filesystem actually happens at any given time. Sort of like locks with databases and such.

What does the last paragraph mean?

Is it correct that in Linux, a file can be written simultaneously by two processes, and the OS doesn't provide implicit synchronization but require explicit synchronization from programmers?

Is lock file such an explicit way which programmers can use to to synchronize the access to the same file by multiple processes?

Thanks.

https://unix.stackexchange.com/a/12818/674 says

Lock files are used by programs to ensure two (well-behaved) separate instances of a program, which may be running concurrently on one system, don't access something else at the same time. The idea is before the program accesses its resource, it checks for presence of a lock file, and if the lock file exists, either error out or wait for it to go away. When it doesn't exist, the program wanting to "acquire" the resource creates the file, and then other instances that might come across later will wait for this process to be done with it. Of course, this assumes the program "acquiring" the lock does in fact release it and doesn't forget to delete the lock file.

This works because the filesystem under all UNIX-like operating systems enforces serialization, which means only one change to the filesystem actually happens at any given time. Sort of like locks with databases and such.

What does the last paragraph mean?

Is it correct that in Linux, a file can be written simultaneously by two processes, and the OS doesn't provide implicit synchronization but require explicit synchronization from programmers?

Is lock file such an explicit way which programmers can use to synchronize the access to the same file by multiple processes?

Thanks.

https://unix.stackexchange.com/a/12818/674 says

Lock files are used by programs to ensure two (well-behaved) separate instances of a program, which may be running concurrently on one system, don't access something else at the same time. The idea is before the program accesses its resource, it checks for presence of a lock file, and if the lock file exists, either error out or wait for it to go away. When it doesn't exist, the program wanting to "acquire" the resource creates the file, and then other instances that might come across later will wait for this process to be done with it. Of course, this assumes the program "acquiring" the lock does in fact release it and doesn't forget to delete the lock file.

This works because the filesystem under all UNIX-like operating systems enforces serialization, which means only one change to the filesystem actually happens at any given time. Sort of like locks with databases and such.

What does the last paragraph mean?

Is it correct that in Linux, a file can be written simultaneously by two processes, and the OS doesn't provide implicit synchronization but require explicit synchronization from programmers?

Is lock file an explicit way to synchronize the access to the same file by multiple processes?

Thanks.

Source Link
Tim
  • 106.8k
  • 234
  • 650
  • 1.1k

Do the filesystem under Linux enforce serialization, which means only one change to the filesystem actually happens at any given time?

https://unix.stackexchange.com/a/12818/674 says

Lock files are used by programs to ensure two (well-behaved) separate instances of a program, which may be running concurrently on one system, don't access something else at the same time. The idea is before the program accesses its resource, it checks for presence of a lock file, and if the lock file exists, either error out or wait for it to go away. When it doesn't exist, the program wanting to "acquire" the resource creates the file, and then other instances that might come across later will wait for this process to be done with it. Of course, this assumes the program "acquiring" the lock does in fact release it and doesn't forget to delete the lock file.

This works because the filesystem under all UNIX-like operating systems enforces serialization, which means only one change to the filesystem actually happens at any given time. Sort of like locks with databases and such.

What does the last paragraph mean?

Is it correct that in Linux, a file can be written simultaneously by two processes, and the OS doesn't provide implicit synchronization but require explicit synchronization from programmers?

Is lock file such an explicit way which programmers can use to synchronize the access to the same file by multiple processes?

Thanks.