#include
#include
#include
int main()
{
int pid, fd[2];
char buffer[1024];
if(pipe(fd) <0)
perror( "pipe() call false!\n ");
if((pid=fork())==-1)
perror( "fork() call false!\n ");
if(pid==0)
{
close(fd[1]);
printf( "Process: %d, stdin:\n ", getpid());
dup2(fd[0], 0);
close(fd[0]);
if(execl( "/bin/pwd", "pwd", (char*)0)==-1)
perror( "execl() call false!\n "); }
else
{
close(fd[0]);
printf( "Process: %d, you can put any text below:\n ", getpid());
dup2(fd[1], 1);
close(fd[1]);
int w;
wait(&w);
//while(gets(buffer)!=NULL)
// puts(buffer);
scanf(buffer);
printf("%s");
}
}
阅读(593) | 评论(0) | 转发(0) |