zoukankan      html  css  js  c++  java
  • 命名管道-----消费者

    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <string.h>
    #include <fcntl.h>
    #include <limits.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    
    #define FIFO_NAME "/tmp/my_fifo"
    #define BUFFER_SIZE PIPE_BUF
    
    int main() {
    	int pipe_fd;
    	int res;
    	int open_mode = O_RDONLY;
    	char buffer[BUFFER_SIZE + 1];
    	int bytes_read = 0;
    
    	memset(buffer, '', sizeof(buffer));
    
    	printf("Process %d opening FIFO O_RDONLY
    ", getpid());
    	pipe_fd = open(FIFO_NAME, open_mode);
    	printf("Process %d result %d
    ", getpid(), pipe_fd);
    
    	if(pipe_fd != -1) {
    		do {
    			res = read(pipe_fd, buffer, BUFFER_SIZE);
    			bytes_read += res;
    		} while(res > 0);
    		(void)close(pipe_fd);
    	} else {
    		exit(EXIT_FAILURE);
    	}
    	printf("Process %d finished, %d bytes read
    ", getpid(), bytes_read);
    	exit(EXIT_SUCCESS);
    }


  • 相关阅读:
    qt动态加载UI文件
    Qt常见控件和操作
    MySQL
    tomcat
    linux iptables基础
    linux 网络基础
    linux CA及OpenSSL学习
    k8s 访问控制
    k8s 存储卷
    docker 安装部署
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3196617.html
Copyright © 2011-2022 走看看