我编写了以下几行代码,在Linux OS下用C语言配置信号量:
int semid = semget(1234 , 1 , IPC_CREAT | 0666);
if(semid < 0)
printf("ERROR in semget \n ");
if( semctl(semid, 0, SETVAL, 1) < 0)
{
printf("ERROR in setting value of semaphore \n");
exit(EXIT_FAILURE);
}
但问题是,我的程序总是显示消息:ERROR in semget
ERROR in setting value of semaphore
,我不知道为什么?