⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p11-7.c

📁 SUN Solaris8平台下进程间通信
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <limits.h>#define FIFO_FILE       "myfifo"int main(void){    int fifo_fd, n, total_bytes = 0;    char readbuf[PIPE_BUF+1];    /* 如果FIFO不存在,创建它*/    if (access(FIFO_FILE, F_OK) == -1) {        if (mkfifo(FIFO_FILE, 0666) != 0) {            printf( "Could not create fifo %s\n", FIFO_FILE);            exit(EXIT_FAILURE);        }    }    /* 打开此FIFO文件 */    if ((fifo_fd = open(FIFO_FILE, O_RDONLY)) <0 ){        printf( "Could not open fifo %s\n", FIFO_FILE);        exit(EXIT_FAILURE);    }    printf("Process %d opened: %s\n", getpid(), FIFO_FILE);    while( (n = read(fifo_fd, readbuf, PIPE_BUF)) > 0 ){        printf("%d received %d bytes\n", getpid(), n);        total_bytes +=n;    }    close(fifo_fd);    printf("Process %d received %d bytes then finished\n", getpid(),total_bytes);    return(EXIT_SUCCESS);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -