#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main()
{
int fd[2];
pid_t childpid;
char string[] = "Hello, world!\n";
char readbuffer[80];
pipe(fd);
childpid = fork();
if (childpid == 0)
{
close(fd[0]);
write(fd[1], string, strlen(string));
// close(fd[1]); удалили
exit(0);
}
else
{
close(fd[1]);
while (read(fd[0], readbuffer, sizeof(readbuffer)) > 0)
{
printf("%s", readbuffer);
}
close(fd[0]);
wait(NULL);
}
return 0;
}