Originally Posted by imrantechi
i m not so well versed with linux, so can you provide a little more explanation ,
so that even people like us also can understand.
See to understand the program first u need to have an idea of shared memory
Shared memory comes under Inter-Process Communication.
Shared memory is the fastest of all IPC.
Shared memory comes under System V IPC.
Shared memory is one of the three System V IPC.
It allows two unrelated processes to access the same logical memory.
Shared memory is a very efficient way of transferring data between two running processes.
In the program i have used these functions.
shmget and shmat for shared memory.
shmget is used to create shared memory.
shmat is used to attach the shared memory to the address space of the process.
When we come to the program,i have created two process i.e process-1 and process-2.
process-1 and process-2 uses same memory i.e shared memory.
I have created a single bit shared memory to control the two process not to access the shared memory at a time.
When process-1 uses the shared memory then process-2 waits until process-1 completes its work and wise versa .
Run the two process at a time (i.e in two terminals ) and u will observe that When process-1 uses the shared memory then process-2 waits until process-1 completes its work and wise versa .