Tuesday, June 10, 2014

C PROGRAM THAT ILLUSTRATES HOW TO EXECUTE TWO COMMANDS CONCURRENTLY WITH A COMMAND PIPE


To execute two commands concurrently with a command Pipe..........
#include<stdio.h>
#include<fcntl.h>
main()
{
int pfd[2],p;
pipe(pfd);
p=fork();
if(p==0)//for child
{
close(pfd[0]);
close(1);
dup(pfd[1]);
execlp("ls","ls","-l",(char *)0);
}
else
{
close(pfd[1]);
close(0);
dup(pfd[0]);
execlp("wc","wc",(char *)0);
}
}

0 comments:

Post a Comment