Linux System Programming-(Part-9) - Full-Duplex Communication using Semaphore and Shared Memory

TechoGenius
TechoGenius
1.2 هزار بار بازدید - 3 سال پیش - This session will guide you
This session will guide you to understand the full duplex communication using semaphore and shared memory.

Explore our Website: www.techogenius.com
Email us at [email protected]/ [email protected]
Like us on Facebook @ Facebook: TechoGeniusAcademy
Follow us on Instagram @ Instagram: techogenius_academy
Subscribe to our channel @ techogeniusacademy

Semaphore allows the processes to synchronize their action.

Usage : Semaphore is use to synchronize access to a block of shared memory in order to prevent one process from accessing the shared memory at the same time  when another process updating it.
Semaphore is kernel maintain integer whose value is restricted to being greater than or equal to zero.
Various operations can be performed on semaphore:
setting the semaphore to the absolute value.
Adding a number to the current value of semaphore.
Subtracting a number from current value of semaphore.
Waiting for semaphore value equal to zero.

Shared Memory :- It allows the two or more processes to share the same region of physical memory. One Process copies the data into shared memory, that data is immediately available to all other process sharing the same segment. This provides the fastest IPC.
Functions  involved in shared memory :-
shmget() :- It is useful for creating as well as opening the shared memory segments. This call returns a shared memory identifier for use in later calls.
shmat() :- It is useful to attach the shared memory segment, this makes the segment part of virtual memory of calling process.
shmdt() :- It is useful for detaching the shared memory segment.
shmctl() :- It is useful for deleting the shared memory segment. The segment will be destroyed only after all the currently attached process have detached. Only one process needs to perform this step.
Critical section of code : A part of program where we are trying to access the shared resource.
Dead Lock Situation : When two or more process want to acquire other resource and its not available,so that will block.
3 سال پیش در تاریخ 1400/02/09 منتشر شده است.
1,269 بـار بازدید شده
... بیشتر