разные выводы
запустил код на сайте ideone.com
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
int fd[2], result;
size_t size;
char resstring[14];
if(pipe(fd) < 0)
{
printf("Can\'t create pipe\n");
exit(-1);
}
result = fork();
if(result < 0)
{
printf("Can\'t fork child\n");
exit(-1);
}
else if (result > 0)
{
/* процесс-предок*/
close(fd[0]);
printf("Father is going to send a letter to his beloved son...\n");
size = write(fd[1], "Hello, world!", 14);
if(size != 14)
{
printf("Can\'t write all string\n");
exit(-1);
}
close(fd[1]);
printf("Father wants his letter to reach the final destination.\n");
printf("Parent exit\n");
}
else {
/* процесс - потомок*/
close(fd[1]);
printf("Son decides to check his inbox...\n");
size = read(fd[0], resstring, 14);
if(size < 0)
{
printf("Can\'t read string\n");
exit(-1);
}
printf("Son has just recieved a nice letter from his father.\n");
printf("Here it is:\n");
printf("\"%s\"\n",resstring);
close(fd[0]);
}
getchar();
return 0;
}
Father is going to send a letter to his beloved son...
Father wants his letter to reach the final destination.
Parent exit
Son decides to check his inbox...
Son has just recieved a nice letter from his father.
Here it is:
«Hello, world!»
а когда запустил код под линуксе
такой результат:
Father is going to send a letter to his beloved son...
Son decides to check his inbox...
Father wants his letter to reach the final destination.
Parent exit
Son has just recieved a nice letter from his father.
Here it is:
«Hello, world!»
В чем же проблем?? Мне надо чтобы код запустил под линуксом выдал результат как на сайте ideone.com
т.е
Father is going to send a letter to his beloved son...
Father wants his letter to reach the final destination.
Parent exit
Son decides to check his inbox...
Son has just recieved a nice letter from his father.
Here it is:
«Hello, world!»
Исправьте,плиз