此函数有三个或四个参数,具体取决于 cmd。当有四个参数时,第四个参数的类型为 union semun。调用程序必须按如下方式定义此联合体
union semun {
int val; /* Value for SETVAL */
struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
unsigned short *array; /* Array for GETALL, SETALL */
struct seminfo *__buf; /* Buffer for IPC_INFO
(Linux specific) */
};
semid_ds 数据结构在 <sys/sem.h> 中定义如下
struct semid_ds {
struct ipc_perm sem_perm; /* Ownership and permissions
time_t sem_otime; /* Last semop time */
time_t sem_ctime; /* Last change time */
unsigned short sem_nsems; /* No. of semaphores in set */
};
struct seminfo {
int semmap; /* # of entries in semaphore map;
unused */
int semmni; /* Max. # of semaphore sets */
int semmns; /* Max. # of semaphores in all
semaphore sets */
int semmnu; /* System-wide max. # of undo
structures; unused */
int semmsl; /* Max. # of semaphores in a set */
int semopm; /* Max. # of operations for semop() */
int semume; /* Max. # of undo entries per
process; unused */
int semusz; /* size of struct sem_undo */
int semvmx; /* Maximum semaphore value */
int semaem; /* Max. value that can be recorded for
semaphore adjustment (SEM_UNDO) */
};