当前位置: 技术问答>linux和unix
关于ftok()提示No such file or directory的问题???
来源: 互联网 发布时间:2016-03-30
本文导语: #define FRAMECOUNTER "/tmp" #define FRAMECOUNTER "/sem" 程序片段: key = ftok(FRAMECOUNTER,1); if(key == -1) { perror("ftok( ) framecounter err"); return -1; } //创道共享内存,用于数据帧计数器 shm_id = shmget(key,sizeof(long),IPC_CREAT|0666);//...
#define FRAMECOUNTER "/tmp"
#define FRAMECOUNTER "/sem"
程序片段:
key = ftok(FRAMECOUNTER,1);
if(key == -1)
{
perror("ftok( ) framecounter err");
return -1;
}
//创道共享内存,用于数据帧计数器
shm_id = shmget(key,sizeof(long),IPC_CREAT|0666);//|S_IRWXU|S_IRWXG
pul_fseq = (long *)shmat(shm_id,(void *)0,0);
*pul_fseq = 1;
if(shmdt(pul_fseq) == -1)
{
perror("shmdt( ) err");
return -3;
}
com_fd = com_open(COMNAME, O_RDWR | O_NONBLOCK);
if(com_fd == -1)
{
perror("com_open( ) err");
return -4;
}
rs232_fd = com_fd;
ret = com_init(com_fd, 0,8,1, 'n');
if(ret != 1)
{
perror("com_init( ) err");
return -5;
}
printf("run here1n");
key = ftok(SEMNAME,1);
if(key == -1)
{
perror("ftok( ) semname err");
return -6;
}
很不解,为什么第一个ftok可以,到第二次ftok时就不行呢???提示No such file or directory.
#define FRAMECOUNTER "/sem"
程序片段:
key = ftok(FRAMECOUNTER,1);
if(key == -1)
{
perror("ftok( ) framecounter err");
return -1;
}
//创道共享内存,用于数据帧计数器
shm_id = shmget(key,sizeof(long),IPC_CREAT|0666);//|S_IRWXU|S_IRWXG
pul_fseq = (long *)shmat(shm_id,(void *)0,0);
*pul_fseq = 1;
if(shmdt(pul_fseq) == -1)
{
perror("shmdt( ) err");
return -3;
}
com_fd = com_open(COMNAME, O_RDWR | O_NONBLOCK);
if(com_fd == -1)
{
perror("com_open( ) err");
return -4;
}
rs232_fd = com_fd;
ret = com_init(com_fd, 0,8,1, 'n');
if(ret != 1)
{
perror("com_init( ) err");
return -5;
}
printf("run here1n");
key = ftok(SEMNAME,1);
if(key == -1)
{
perror("ftok( ) semname err");
return -6;
}
很不解,为什么第一个ftok可以,到第二次ftok时就不行呢???提示No such file or directory.
|
[code=BatchFile]The ftok() function uses the identity of the file named by the given path-
name (which must refer to an existing, accessible file) and the least sig-
nificant 8 bits of proj_id (which must be non-zero) to generate a key_t
type System V IPC key, suitable for use with msgget(2), semget(2), or
shmget(2).[/code]
/sem目录你必须至少有读权限。
权限问题考虑了么?
name (which must refer to an existing, accessible file) and the least sig-
nificant 8 bits of proj_id (which must be non-zero) to generate a key_t
type System V IPC key, suitable for use with msgget(2), semget(2), or
shmget(2).[/code]
/sem目录你必须至少有读权限。
权限问题考虑了么?
|
直接定义可能会产生冲突的。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。