Shared File and Shared Memory IPC Flashcards
What are locks?
Locks are used to control access to a shared file to prevent data corruption.
What is an exclusive lock?
Only one process can acquire the lock at a time.
Used for write operations to ensure no other process reads or writes to the file simultaneously.
What are shared locks?
Multiple processes can acquire the lock simultaneously.
Used for read-only access since multiple readers won’t interfere with each other.
What is a mutex and what does it do? (mutual exclusion)
Ensures that only one process or thread can access the shared resource at a time.
Typically binary (locked/unlocked).
Simpler and lightweight when compared to semaphores.
Use Case: Protect critical sections in shared memory.
What are semaphores and what do they do?
Can allow multiple processes/threads to access a resource up to a set limit.
Two main operations:
Wait/Decrement (P): Decreases the semaphore’s value. Blocks if the value is 0.
Signal/Increment (V): Increases the semaphore’s value, potentially unblocking waiting processes.
Use Case: Limiting access to a shared resource (e.g., database connections)