Добро пожаловать! Это — архивная версия форумов на «Хакер.Ru». Она работает в режиме read-only.
 

fork и pipe

Пользователи, просматривающие топик: none

Зашли как: Guest
Все форумы >> [Компилируемые языки] >> fork и pipe
Имя
Сообщение << Старые топики   Новые топики >>
fork и pipe - 2007-04-10 11:03:03.323333   
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!

Что делать?
Post #: 1
Страниц:  [1]
Все форумы >> [Компилируемые языки] >> fork и pipe







Связаться:
Вопросы по сайту / xakep@glc.ru

Предупреждение: использование полученных знаний в противозаконных целях преследуется по закону.