hp Unix 上 union semun编译不过的问题解决

本文解决Linux环境下信号灯(semaphore)编译错误的问题,包括union semun定义缺失及seminfo结构体成员错误,并提供正确的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux环境进程间通信(四)信号灯

http://www.ibm.com/developerworks/cn/linux/l-ipc/part4/

 

今天对文中的例子进行了编译,发现 union   semun编译不过,经过调查发现sem.h中竟然把声明给注释掉了。

所以需要自己追加对union   semun 定义。

union   semun
      {
          int   val;
          struct   semid_ds   *buf;
          unsigned   short   int   *array;
          struct   seminfo   *__buf;
      };

 

还有

arg.__buf->semmap

->

 修正为 arg.__buf->pad。

 

我们可以看看sem.h中部分定义如下:

    /* The fourth argument to semctl() is optional and varies depending
     * on the value of its first argument.  If required, it is of type
     * "union semun" which the application program must explicitly declare:
     *
     *  union semun {  被注释掉了
     *          int val;
     *          struct semid_ds *buf;
     *          unsigned short *array;
     *  } arg

 

还有seminfo 的定义如下

 

/*
** semaphore information structure
*/
   struct       seminfo {
        int        pad;         /* pad field to replace obsolete semmap of SysV */ 是pad哦
        int     semmni;         /* # of semaphore identifiers */
        int     semmns;         /* # of semaphores in system */
        int     semmnu;         /* # of undo structures in system */
        int     semmsl;         /* max # of semaphores per ID */
        int     semopm;         /* max # of operations per semop call */
        int     semume;         /* max # of undo entries per process */
        int     semusz;         /* size in bytes of undo structure */
        int     semvmx;         /* semaphore maximum value */
        int     semaem;         /* adjust on exit max value */
   };

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值