开始学liunx遇到一些小问题求解决
#include"stdio.h"#include"stdlib.h"
#include"sys/types.h"
#include"string.h"
main()
{
pid_t pid;
int pipes[2];
char data[]="hello snow";
char num[256];
if(pipe(pipes)<0)
{
printf("eroor");
exit(0);
}
if(pid=fork()==-1)
{
printf("error");
exit(0);
}
else if(pid==0)
{
if((write(pipes[1],data,strlen(data)))==-1)
{
printf("error");
exit(0);
}
else
{
printf("OK %s\n",data);
}
}
else
{
sleep(1);
if((read(pipes[0],num,strlen(data)))==-1)
{
printf("error");
exit(0);
}
else
{
printf("ya ma de");
wait(NULL);
}
}
}
为什么呢,按照常理应该是
OK hello snow
ya ma de
求解决