|
我的程序意思是这样的。
1.只申请一个信号量 semsid
2.通过semctl(semid,SEMFIRST,IPC_STAT,mysem),把信号量的标识符的数据结构放到 mysem.buf中
3.通过信号量标识符中的sem_perm结构得到信号量的key
这是我的程序
#define SEMNUM 1
#define SEMFIRST 0
#include<sys/ipc.h>
#include<sys/types.h>
#include<sys/sem.h>
#include<sys/shm.h>
#if defined(__GNU_LIBRARY__)&&! defined(_SEM_SEMUN_UNDEFINED)
#else
union semun
{
int val;
struct semid_ds *buf;
unsigned short int * array;
struct seminfo *__buf;
};
#endif
int main()
{
union semun mysem;
int semid;
struct ipc_perm t;
semid=semget(IPC_PRIVATE,SEMNUM,0666);
/*get the room for the data structure semid_ds
*/
mysem.buf=(struct semid_ds*)malloc(sizeof(struct semid_ds));
/*get the initial value of the semaphore
*/
semctl(semid,SEMFIRST,IPC_STAT,mysem));
printf("\nthe key of semaphore recieved from \"ipc_perm\"l\n",mysem.buf->sem_perm.key);
}
问题是:
我编译的时候报错 说:error: structure has no member named `key'
但是我看了ipc.h中struct sem_perm中 是有key的。
我想问问高手这是为什么? |
|