procwrite.c
来自「LINUX C编程实战这本书附带光盘的原代码」· C语言 代码 · 共 33 行
C
33 行
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FIFO_NAME "myfifo"
#define BUF_SIZE 1024
int main(void)
{
int fd;
char buf[BUF_SIZE] = "Hello procwrite, I come from process named procread!";
umask(0);
if (mkfifo (FIFO_NAME, S_IFIFO | 0666) == -1)
{
perror ("mkfifo error!");
exit (1);
}
if((fd = open (FIFO_NAME, O_WRONLY) ) == -1)/*以写方式打开FIFO*/
{
perror ("fopen error!");
exit (1);
}
write (fd, buf, strlen(buf)+1); /*向FIFO写数据*/
close (fd);
exit (0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?