p11-8.c

来自「SUN Solaris8平台下进程间通信」· C语言 代码 · 共 29 行

C
29
字号
#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <sys/stat.h>#include <unistd.h>#include "err_exit.h"#define FIFO_FILE       "myfifo"#define TEN_MEG          1024*1024*10int main(void){    int fifo_fd, i, n, total_bytes = 0;    char sendbuf[PIPE_BUF+1];    /* 打开FIFO文件 */    if ((fifo_fd = open(FIFO_FILE, O_WRONLY)) <0 ){        printf( "Could not open fifo %s\n", FIFO_FILE);        exit(EXIT_FAILURE);    }    printf("Process %d opened: %s\n", getpid(), FIFO_FILE);    do {        if ((n = write(fifo_fd, sendbuf, PIPE_BUF)) == -1)             err_exit("FIFO broken");        printf(" %d write %d bytes\n", getpid(),n);        total_bytes += n;    }while (total_bytes < TEN_MEG);    close(fifo_fd);    printf("Process %d finished\n", getpid());    return(EXIT_SUCCESS);}

⌨️ 快捷键说明

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