2010年(30)
分类: LINUX
2010-06-25 18:00:06
#include
#include
#include
#include
#include
int main()
{
pid_t childpid
int fd[2];
char string[] = "data from child process";
char tmp[100];
childpid = fork();
switch(childpid)
{
case -1:
printf("fork error.\n");
break;
case 0:
printf("fork ok, I am the child.\n");
close(fd[0]);//0->in 1->out 2->stderr
write(fd[1], string, strlen(string));
exit(0);
default:
printf("I am the father.\n");
close(fd[1]);
read(fd[0], tmp, sizeof(tmp));
printf("now buf is %s\n", tmp);
}
return 0
} |
|