首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

循序渐进学unix——下机记录(三)

2012-11-26 
循序渐进学unix——上机记录(三)#includestdio.h#includeunistd.h#includestdlib.h#include sys/type

循序渐进学unix——上机记录(三)

#include<stdio.h>#include<unistd.h>#include<stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>void main(int argc, char** argv){char a = 'a';char b = 'b';char rcv;FILE* fd;int tube[2];int tube2[2];pipe(tube);pipe(tube2);if(fork()==0) {//Section filsdup2(tube[1], 1);dup2(tube2[0], 0);close(tube[1]);close(tube2[0]);printf("a");fflush(stdout);//read(0, &rcv, 1);scanf("%c",&rcv);fprintf(fdopen(2, "w"), "filsfilsbbb\n");//fd = fopen("fils.txt", "w");//fd = fopen("fils.txt", O_CREAT | O_WRONLY);//fprintf(fd, "Fils : receive b\n");//write(tube[1], &a, 1);exit(0);} else {//peredup2(tube[0], 0);dup2(tube2[1], 1);close(tube[0]);close(tube2[1]);//read( 0, &rcv, 1);scanf("%c", &rcv);fprintf(stderr, "perepereaaa\n");//fd = fopen("pere.txt", O_CREAT | O_WRONLY);//fd = fopen("pere.txt", "w");//fprintf(fd, "receive a\n");printf("b");//printf("Père : read du tube :%c. Lire le char suivant.\n", rcv);//read( tube[0], &rcv, 1);//printf("Père : read du tube :%c. \n", rcv);}}

哦了,先贴到这,后半部分晚些时候再上。

热点排行