10.3.5 控制信号量——第三个参数详解
控制信号量的函数为semctl函数,其定义如下:
int semctl(int semid, int semnum, int cmd,/* union semun arg*/);
某些特定的操作需要第四个参数,第四个参数是联合体,很不幸的是这个联合体需要程序员自己定义,代码如下所示:
union semun {
int val; /* value for SETVAL */
struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
u_short *array; /* array for GETALL & SETALL */
};
根据第三个参数cmd值的不同,semctl支持以下命令:
结构体semid_ds
struct semid_ds{
struct ipc_perm sem_perm; /* operation permission struct */
struct sem *sem_base; /* ptr to array of semaphores in set */
uishort sem_nsems; /* #of semaphores in set */
time_t sem_otime; /* time of last semop() */
time_t sem_ctime; /* time of creation or last IPC_SET */
};
1.IPC_RMID
semctl函数的第二个参数被忽略。和消息队列的删除一样,内核不会维护

本文详细介绍了Linux系统中控制信号量的semctl函数,包括IPC_RMID、IPC_STAT、IPC_SET、GETVAL、SETVAL、GETALL和SETALL等命令的用法,以及在不同命令下如何操作信号量集的参数。
最低0.47元/天 解锁文章
498

被折叠的 条评论
为什么被折叠?



