当前位置: 技术问答>linux和unix
wait和waitpid
来源: 互联网 发布时间:2017-05-26
本文导语: /*与服务器建立了5个连接的TCP客户程序*/ #include "unp.h" int main(int argc, char **argv) { int i, sockfd[5]; struct sockaddr_in servaddr; if (argc != 2) err_quit("usage: tcpcli "); for (i = 0; i 0) printf("child %d terminatedn", pid); return; } /*...
/*与服务器建立了5个连接的TCP客户程序*/
#include "unp.h"
int
main(int argc, char **argv)
{
int i, sockfd[5];
struct sockaddr_in servaddr;
if (argc != 2)
err_quit("usage: tcpcli ");
for (i = 0; i 0)
printf("child %d terminatedn", pid);
return;
}
/*服务器程序*/
#include "unp.h"
int
main(int argc, char **argv)
{
int listenfd, connfd;
pid_t childpid;
socklen_t clilen;
struct sockaddr_in cliaddr, servaddr;
void sig_chld(int);
listenfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT);
Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));
Listen(listenfd, LISTENQ);
Signal(SIGCHLD, sig_chld); /* 在这里注册信号处理函数must call waitpid() */
for ( ; ; ) {
clilen = sizeof(cliaddr);
if ( (connfd = accept(listenfd, (SA *) &cliaddr, &clilen)) 0)
printf("child %d terminatedn", pid);
return;
}
但是也能正常工作。
那么书中指的是什么意思?
|
wait 没有 WNOHANG 参数,可能会阻塞,达不到循环效果
http://www.cnblogs.com/yuxingfirst/p/3165407.html
http://blog.csdn.net/liuxingbangly/article/details/22398931
http://www.cnblogs.com/yuxingfirst/p/3165407.html
http://blog.csdn.net/liuxingbangly/article/details/22398931
|
It might...