struct sem {

int semval;

int sempid;

□ sem_otime specifies the time of the last access to the semaphore in jiffies (including, e.g., information queries). sem_ctime specifies the time the semaphore value was last changed.

□ sem_pending points to a linked list of pending semaphore operations. The list consists of sem_queue instances. sem_pending_last is used to quickly access the last element in the list, whereas sem_pending points to the start of the list.

Figure 5-2 shows the interplay between the data structures involved.

struct ipc_ids struct ipc_ids

ID to pointer mapping



1 1






ID to pointer mapping

Figure 5-2: Interplay between the semaphore data structures.


Figure 5-2: Interplay between the semaphore data structures.

Starting from the sem_ids instance obtained from the current namespace, the kernel travels via ipcs_idr to the ID-to-pointer database and looks up the required instance of kern_ipc_perm. The kern_ipc_perm entry can be type-cast into an instance of type sem_array. The current status of the semaphore is indicated by linking with two further structures.

□ The pending operations are managed in a linked list of sem_queue instances. Processes that are sleeping while waiting for operation execution can also be determined from this list.

□ An array of struct sem instances is used to hold the values of the individual semaphores of the set.

Not shown is the information for managing undo operations because it is not particularly interesting and would complicate matters unnecessarily.

kern_ipc_perm is the first element of the data structure for managing IPC objects not only for semaphores but also for message queues and shared memory objects. It enables the kernel to use the same code to check access permissions in all three cases.

Each sem_queue element contains a pointer to an array of sem_ops instances that describe in detail the operations to be performed on the semaphore. (An array of sem_ops instances is used because several operations can be performed on the semaphores in a semaphore set using a single semctl call.)

Continue reading here: Info

Was this article helpful?

0 0