I have another a problem while writing to child and then reading the result:
In the child process I redirect stdout of the process to the pipe's write. So when I read in the parent's process I should have a sorted list but I receive not sorted and what is more, the program doesn't ends.
if(fork() == 0)
dup2(fd, 1); //stdout -> pipe's write (everything what would go to stdout will go to the pipe's write...
execlp("sort", "sort", NULL);
write(fd, "c\n", 2);
write(fd, "a\n", 2);
write(fd, "b\n", 2);
while((c = read(fd, buf, 5)) > 0)
write(1, buf, c);