![使用fork的str_cli函数 使用fork的str_cli函数](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
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;
}