/*-------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");
//dup(pipefd[0]);
close(pipefd[0]);
pipe_write(pipefd[1]);
//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(pipefd[1]);
pipe_read(pipefd[0]);
wait(NULL);
exit(0);
}
return 0;
}
小白笔记-------------pipe管道(1)(后续还有哦)
最新推荐文章于 2023-03-20 18:23:08 发布