ВУЗ:
Составители:
268
printf("Parent: Creating child process...\n");
if ((childpid = fork()) == 0) { // child process starts
printf("Child: Child process created...\n");
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)
{
Страницы
- « первая
- ‹ предыдущая
- …
- 266
- 267
- 268
- 269
- 270
- …
- следующая ›
- последняя »
