Здравствуйте! Пытаюсь передать стринг между двумя дочерними процессами. ниже листинги программ. В чем проблема? на линуксе недавно программирую.
pipe.c
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
#include<string.h>
int main( int argc, char *argv[], char *envp)
{
int fd[2], result, result1;
char resstring[14];
if (pipe<0)
{
printf("Can't creat pipe\n");
exit(-1);
}
result=fork();
if (result<0)
{
printf("Can't fork child1\n");
exit(-1);
}
else if (result==0)
{
result1=fork();
if (results1<0)
{
printf("Can't fork child2\n");
exit(-1);
}
else if (result==0)
{
execle("root/child2","root/child2",0,envp);
}
else
{
printf("This is child1\n");
close(fd[1]);
size=read(fd[0],resstring,14);
if (size!=14)
{
printf("Can't read all string\n");
exit(-1);
}
close(fd[0]);
printf("%s",resstring);
}
}
else
{
printf("This is parent\n");
exit(-1);
}
return 0;
}
child2.c
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
#include<string.h>
int main( i)
{
int fd[2];
size_t size;
char resstring[14]={"HELLO, WORLD!"};
close(fd[0);
size=write(fd[1],resstring,14);
if (size!=14)
{
printf("Can't write all string\n");
exit(-1);
}
close(fd[1]);
return 0;
}
При запуске выдает сообщения:
This is child2
Can't write string
This is child1
This is parent
Can't read all string