ВУЗ:
Составители:
109
close(pipe1[1]);
close(pipe2[0]);
printf("Child: Starting server...\n");
server(pipe1[0], pipe2[1]);
printf("Child: Terminating process...\n");
exit(0);
}
// parent process
close(pipe1[0]);
close(pipe2[1]);
sleep(2);
printf("Parent: Starting client...\n");
client(pipe2[0],pipe1[1]);
printf("Parent: Waiting for child porecess to terminate a zombie...\n");
waitpid(childpid, NULL, 0);
printf("Parent: Zombie terminated...\n");
return 0;
}
void server(int readfd, int writefd) {
char str[MAXLINE];
strcpy(str,"some string to transmit");
ssize_t n = 0;
printf("%s %s %s","Child: Server: Tranferting string
to client - \"",str,"\"\n");
write(writefd, str, strlen(str));
sleep(1);
printf("Child: Server: Waiting for replay from client...");
while ((n = read(readfd,str,MAXLINE)) > 0)
{
str[n] = 0;
printf("%s %s %s","Received OK from client - \"",str,"\"\n");
break;
Страницы
- « первая
- ‹ предыдущая
- …
- 107
- 108
- 109
- 110
- 111
- …
- следующая ›
- последняя »
