Kernel semid_ds structure
Keywords: lpg

Next: Kernel sem structure Up: Internal Data Structures Previous: Internal Data Structures

#### Kernel `semid_ds` structure

As with message queues, the kernel maintains a special internal data structure for each semaphore set which exists within its addressing space. This structure is of type `semid_ds`, and is defined in `linux/sem.h` as follows:

            /* One semid data structure for each set of semaphores in the system. */
            struct semid_ds {
                    struct ipc_perm sem_perm;       /* permissions .. see ipc.h */
                    time_t          sem_otime;      /* last semop time */
                    time_t          sem_ctime;      /* last change time */
                    struct sem      *sem_base;      /* ptr to first semaphore in array */
                    struct wait_queue *eventn;
                    struct wait_queue *eventz;
                    struct sem_undo  *undo;         /* undo requests on this array */
                    ushort          sem_nsems;      /* no. of semaphores in array */
            };

As with message queues, operations on this structure are performed by a special system call, and should not be tinkered with directly. Here are descriptions of the more pertinent fields:

`sem_perm`

  This is an instance of the `ipc_perm` structure, which is defined for us in `linux/ipc.h`. This holds the permission information for the semaphore set, including the access permissions, and information about the creator of the set (uid, etc).

`sem_otime`

  Time of the last `semop()` operation (more on this in a moment)

`sem_ctime`

  Time of the last change to this structure (mode change, etc)

`sem_base`

  Pointer to the first semaphore in the array (see next structure)

`sem_undo`

  Number of undo requests in this array (more on this in a moment)

`sem_nsems`

  Number of semaphores in the semaphore set (the array)