zoukankan      html  css  js  c++  java
  • 有名管道——读写fifo

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include<unistd.h>
     4 #include<string.h>
     5 #include<sys/types.h>
     6 #include<sys/wait.h>
     7 #include<sys/stat.h>
     8 #include<fcntl.h>
     9 int main(void)
    10 {
    11     int len =0;
    12     char buf[100];
    13     memset(buf,0 ,sizeof(buf));
    14     int fd = open("fifo1",O_RDONLY);
    15     while( (len=read(fd,buf,sizeof(buf))) > 0)
    16     {
    17         printf("%s
    ",buf);
    18     }
    19     close(fd);
    20     return 0;
    21 }
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include<unistd.h>
     4 #include<string.h>
     5 #include<sys/types.h>
     6 #include<sys/wait.h>
     7 #include<sys/stat.h>
     8 #include<fcntl.h>
     9 int main(int arg,char* args[])
    10 {
    11     int len = 0;
    12     char buf[100];
    13     memset(buf,0,sizeof(buf));
    14     int fd = open("fifo1",O_WRONLY);
    15     while(1)
    16     {
    17         scanf("%s",buf);
    18         if(buf[0]=='0')
    19             break;
    20         write(fd,buf,sizeof(buf));
    21     }
    22     close(fd);
    23     return 0;
    24 }
    .SUFFIXES:.c .o
    
    CC=gcc
    SRCS1=myfifo.c
    SRCS2=writefifo.c
    
    OBJS1=$(SRCS1:.c=.o)
    OBJS2=$(SRCS2:.c=.o)
    
    EXEC1=readfifo
    EXEC2=writefifo
    
    
    all: $(OBJS1) $(OBJS2)
        $(CC) -o $(EXEC1) $(OBJS1)
        $(CC) -o $(EXEC2) $(OBJS2)
        @echo '-----------------ok----------------------'
    .c.o:
        $(CC) -Wall -g -o $@ -c $<
    clean:
        -rm -f $(OBJS1)
        -rm -f $(OBJS2)
        -rm -f core*
  • 相关阅读:
    阅读13-17章
    阅读<构建之法>10、11、12章
    作业5.2
    作业5.1
    作业四:构建之法的困惑和思考(5-7)
    做汉堡
    作业三:构建之法的困惑和思考(1-5)
    实验二 合作:王宏财 http://www.cnblogs.com/wanghongcai/
    实验一--四则运算
    数独九宫格
  • 原文地址:https://www.cnblogs.com/leejxyz/p/5713651.html
Copyright © 2011-2022 走看看