使用fork的str_cli函数

时间:2023-03-09 17:12:05
使用fork的str_cli函数

使用fork的str_cli函数

void str_cli(FILE *fp, int sockfd)
{
pid_t pid;
char sendline[MAXLINE], recvline[MAXLINE]; if ( (pid = fork()) == ) { /* child: server -> stdout */
while (read(sockfd, recvline, MAXLINE) > )
fputs(recvline, stdout); kill(getppid(), SIGTERM); /* in case parent still running */
exit();
} /* parent: stdin -> server */
while (fgets(sendline, MAXLINE, fp) != NULL)
writen(sockfd, sendline, strlen(sendline)); shutdown(sockfd, SHUT_WR); /* EOF on stdin, send FIN */
pause();
return;
}