linux系统编程——创建命名管道
FIFO,也称为命名管道,它是一种文件类型,
创建命名管道:mkfifo
man 3 mkfifo
创建命名管道
#include <sys/types.h>
#include <sys/stat.h>
// int mkfifo(const char *pathname, mode_t mode);
int main()
{
mkfifo("./file",0600);
return 0;
}
生成了可读可写的file
判断文件是否存在
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
// int mkfifo(const char *pathname, mode_t mode);
int main()
{
if (mkfifo("./file",0600)==-1 && errno==EEXIST)
{
printf("mkfifo fail\n");
perror("why");
}
else
{
if(errno==EEXIST)
{
printf("file you\n");
}
else
{
printf("mkfifo success\n");
}
}
return 0;
}
注:EEXIST判断文件是否存在
errno调试错误
——@上官可编程