My question is: when the process is abnormally interrupted (via a signal, it can be SIGKILL, so we cannot intercept it), is there a guaranteed order or atomicity in which its resources are freed? In particular, I am interested in file locks and shared memory.
For example:
1) If a process holds locks on 2 files and ends abnormally, is it possible that another process trying to lock the same files sees that one file is locked and the other is unlocked? Or does the process of freeing files block atoms from the point of view of other processes?
If it is not atomic, is there at least a predefined order in which file locks will be released by the completion process (for example, in the reverse order from which they were initially locked)?
2) I wanted to use file locking to ensure the correct initialization of shared memory. Processes mapped to shared memory will contain a common lock, and a new process that wants to map to the same shared memory segment will try to check this lock to see if it needs to be initialized (if necessary, I can provide more detailed information later) .
However, the same question arises here: if the process that contains the file lock and is also displayed in the shared memory segment is abnormally interrupted, is it possible that after the shared memory is automatically turned off, other processes will still see the file lock as locked ? Or is it a decoupling of the shared memory segment and unlocking the file atom from the point of view of other processes?
c multithreading unix shared-memory ipc
Yevgeniy p
source share