分类: LINUX
2010-07-01 18:00:13
#include
#include
#include
int main()
{
pid_t pid;
int fds[2];
if((pipe(fds))==-1)
{
perror("pipe error");
exit(EXIT_FAILURE);
}
else
{
pid=fork();
if(pid==-1)
{
perror("fork error");
exit(EXIT_FAILURE);
}
else if(pid==0)
{
close(fds[0]);//close the parent prcoess writer operation
dup2(fds[1],1);//read the data from the pipe
execlp("ls","ls","--help",NULL);
perror("dup2 error");
exit(EXIT_SUCCESS);
}
else if(pid > 0)
{
close(fds[1]);//close the parent prcoess writer operation
dup2(fds[0],0);//read the data from the pipe
execlp("more","more",NULL);
perror("dup2 error");
exit(EXIT_FAILURE);
}
}
return 0;
}