OSL Assignment 8
OSL Assignment 8
Attaching to the Shared Memory Segment: The Processes that need to access the
shared memory attach themselves to this segment using shmat() system call. Once
attached the processes can directly read from and write to the shared memory.
How Shared Memory IPC Works?
Detaching and Deleting the Segment: When a process no longer needs access to the
shared memory it can detach from the segment using shmdt() system call. The shared
memory segment can be removed entirely from system using shmctl() once all processes
have the detached.
Used System Calls
The system calls that are used in the program are:
Function Signature Description
int shmget(key_t key,size_t size, int Upon successful completion, shmget() returns an identifier for the
shmflg); shared memory segment.
shmget()
Before you can use a shared memory segment, you have to attach
void *shmat(int shmid ,void *shmaddr ,int yourself to it using shmat(). Here, shmid is a shared memory ID
shmflg); and shmaddr specifies the specific address to use but we should set
shmat() it to zero and OS will automatically choose the address.
When you’re done with the shared memory segment, your program
int shmdt(void *shmaddr); should detach itself from it using shmdt().
shmdt()