读书人

这么简单的sem_int竟然失败,该怎么解决

发布时间: 2012-02-12 17:16:33 作者: rapoo

这么简单的sem_int竟然失败
/*testSemp文件内容如下*/
#include <semaphore.h>

static sem_t semVal;
int main()
{
int nVal;
sem_init(&semVal,0,nVal);
return 1;
}

g++ -o testSemp testSemp.cpp //没有问题
./testSemp //竟然报Bad system call(core dumped)

我是在freebsd上跑的,哪位大哥碰到过?

[解决办法]
ERRORS
The sem_init() function will fail if:
[EINVAL]
The value argument exceeds SEM_VALUE_MAX.
[ENOSPC]
A resource required to initialise the semaphore has been exhausted, or the limit on semaphores (SEM_NSEMS_MAX) has been reached.
[ENOSYS]
The function sem_init() is not supported by this implementation.
[EPERM]
The process lacks the appropriate privileges to initialise the semaphore.
[解决办法]
是否是nVal 没有初始化阿, 你试试 int nVal=0; 看看
[解决办法]
问题不清楚, 我手头没UNIX, 没法给你试试.

读书人网 >UNIXLINUX

热点推荐