大概理解了dup的意思,mark一下
/*-------2015/10/24----------*/
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<string.h>
void pipe_read(int p)
{
char m[100] ;
read(p,m,100);
printf("that: is what we get:%s\n",m);
}
void pipe_write(int p)
{
char m[100] = "aaron";
write(p,m,strlen(m)+1);
}
main(int agrc,char **argv[],char * environ)
{
int p;
pid_t pid;
int pipefd[2];
p = pipe(pipefd);
pid = fork();
if(pid < 0){
printf("error\n");
}
if(pid == 0 )
{
printf("i am a child process\n");
close(0);
dup(pipefd[0]);
close(pipefd[0]);
close(pipefd[1]);
pipe_read(0);
execv("list2",NULL);// The exec() family of functions replaces the current process image witha new process image.
exit(0);
}
if(pid > 0)
{
printf("i am a parent process\n");
close(0);
dup(pipefd[1]);
close(pipefd[1]);
close(pipefd[0]);
pipe_write(0);
wait(NULL);
exit(0);
}
return 0;
}