linux ubuntu 进程间通信 有名管道 open错误:permission denied
int main(int argc,char** argv)
{
int fd;
char w_buf[100];
int nwrite;
/*创建有名管道*/
if((mkfifo(FIFO_SERVER,O_CREAT|O_EXCL|O_RDWR)<0)&&(errno!=EEXIST))
{
printf("cannot create fifoserver\n");
}
/*打开管道*/
fd=open(FIFO_SERVER,O_WRONLY |O_NONBLOCK,0);
if(fd==-1)
{
perror("open");
exit(1);
}
//......
------解决方案--------------------没有权限!!!
------解决方案--------------------fd=open(FIFO_SERVER,O_WRONLY);
改成这样
------解决方案--------------------mkfifo第二个参数是权限, 不是打开方式.
------解决方案--------------------楼上说的是
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define BUFSIZE 40
int main(int argc,char **argv)
{
int fd,n;
char buf[BUFSIZE];
if(argc != 2)
{
printf("Usage:%s [pathname]\n",argv[0]);
exit(1);
}
if(mkfifo(argv[1],0644) < 0)
{
perror("mkfifo");
exit(1);
}
if( (fd = open(argv[1],O_WRONLY)) < 0)
{
perror("open");
exit(1);
}
n = sprintf(buf,"%s from %d","hello",getpid());
write(fd,buf,n+1);
close(fd);