본문 바로가기

IT

pipe1.c

#include <stdio.h>

#include <unistd.h>


main()

{

int len, i, apipe[2];

char buf[BUFSIZ];

if(pipe(apipe)==-1)

{

perror("could not make pipe");

exit(1);

}


printf("Got a pipe! It is file descriptors : [ %d %d] \n",apipe[0],apipe[1]);


while(fgets(buf,BUFSIZ,stdin))

{

len = strlen(buf);

if(write(apipe[1],buf,len)!=len)

{

perror("writing to pipe");

break;

}

for(i=0;i<len;i++)

buf[i]='x';

len = read(apipe[0],buf,BUFSIZ);

if(len==-1)

{

perror("reading from pipe");

break;

}

if(write(1,buf,len)!=len)

{

perror("writing to stdout");

break;

}

}

}



'IT' 카테고리의 다른 글

method2.c  (0) 2014.11.12
method1.c  (0) 2014.11.12
psh3.c  (0) 2014.11.11
psh2.c  (0) 2014.11.11
waitdemo2.c  (0) 2014.11.11