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 */
};