Unit-3
Unit-3
InterProcessCommunication
IPC
IPC
► Pipes
► Shared memory
► Message Queues
► Sockets
► Signals
► Semaphores
Pipes:
► Shared memory allows multiple processes to access the same region of memory,
allowing them to communicate by reading and writing to shared memory locations.
► This provides a fast and efficient means of communication because data can be
transferred between processes without the need for copying.
► However, shared memory requires careful synchronization to prevent race
conditions and ensure data consistency.
Message queues
► Lock Types: UNIX supports two types of locks: advisory locks and mandatory
locks.
• Advisory locks: Processes can request locks, but it's up to other processes to
honor these locks.
• Mandatory locks: The system enforces locks, ensuring that no process can
access the locked portion of the file without appropriate permissions.
File locking
• File locking allows processes to prevent other processes from
accessing a file while it is being used.
• The two main types of file locking in Unix are advisory locking and mandatory
locking.
example
Lock structure
Locking Commands
Locking Process
Unlocking
fl_lock1.c
fl_lock2.c
Program on Record locking
Recordlock –program 1
Recordlock Program 2
Other UNIX locking techniques
FIFOs
► int main() {
► if (clone(NULL, NULL, CLONE_NEWIPC, NULL) == -1) {
► perror("clone");
► return 1;
► }
► // Now in a new IPC namespace
► // Create and manipulate IPC resources here
► return 0;
► }
Benefits of IPC Namespaces
IPC