avaava
Сообщений: 1
Оценки: 0
Присоединился: 2007-04-10 10:54:02.586666
|
Помогите плиз разобраться с fork. Эта програмa: #include <stdio.h> #include <iostream> #include <unistd.h> #include <sys/types.h> int main(void) { int fd, nbytes; pid_t childpid; char string[] = "Hello, world!"; char readbuffer; pipe(fd); if ((childpid = fork()) == -1) { perror("fork"); return(1); } if (childpid == 0) { /* Child process closes up input side of pipe */ close(fd); /* Send "string" through the output side of pipe */ while (!0) { write(fd, string, 15); } return(0); } else { /* Parent process closes up output side of pipe */ close(fd); /* Read in a string from the pipe */ while (!0) { sleep(1); for (int i; i<sizeof(readbuffer); i++) readbuffer<i>=0; nbytes = read(fd, readbuffer, sizeof(readbuffer)); std::cout<<readbuffer<<std::endl; } } return(0); } Выводит вот такую ерунду: Hello, wHello, world! orld! ello, woHello, world! rld! llo, worHello, world! ld! lo, worlHello, world! Что делать?
|