我正在使用命名信号量编写一个多进程程序,在主进程中我使用以下代码打开信号量
semaphore = sem_open("/msema",O_RDWR|O_CREAT|O_TRUNC,00777,1);
if (semaphore == SEM_FAILED)
perror("SEMAPHORE");
在子程序中
count_sem=sem_open("/msema",O_RDWR);
if(count_sem==SEM_FAILED)
{
perror("sem_open");
return 1;
}
在 sem_wait()
do {
errno=0;
printf("BeforeSemWait\n");
rtn=sem_wait(count_sem);
printf("afterSemWait\n");
} while(errno==EINTR);
if(rtn < 0) {
printf("Error\n");
perror("sem_wait()");
sem_close(count_sem);
return 1;
}
我收到来自 sem_wait() 的总线错误
BeforeSemWait
Program received signal SIGBUS, Bus error.
0x00a206c9 in sem_wait@@GLIBC_2.1 () from /lib/libpthread.so.0`
我究竟做错了什么?
编辑:整个代码:master.c:http : //pastebin.com/3MnMjUUM worker.c http://pastebin.com/rW5qYFqg