Please enable JavaScript.
Coggle requires JavaScript to display documents.
Advanced IPC (Semaphores (important operations (p for wait operation, v…
Advanced IPC
Semaphores
-
-A semaphore isn't a form of IPC similar to the others that we've described (pipes, FIFOs, and message queues).
-A semaphore is a counter used to provide access to a shared data object for multiple processes.
-A solution to problem of synchronization
-Semaphore, sem can be seen as an integer variable
-Only one process can ever change sem at any one time-To guarantee synchronization
important operations
-
v for signal operation (don’t confuse with previous signal, it simply means to proceed)
-
To obtain a shared resource, a process needs to do the following:
- Test the semaphore that controls the resource.
- If the value of the semaphore is positive, the process can use the resource. In this case, the process decrements the semaphore value by 1, indicating that it has used one unit of the resource.
- Otherwise, if the value of the semaphore is 0, the process goes to sleep until the semaphore value is greater than 0. When the process wakes up, it returns to step 1.
Message passing
-
message queues
-
-
A message queue is a linked list of messages stored within the kernel and identified by a message queue identifier.
Shared memory
shmget
shmat - Attach memory segment from physical memory to logical data space
shmdt - Detach memory segment from the logical address space
shmctl - Similar to msgctl(), Get or change information
-