让LU留住您的每

一天 让LU博客留住您的每一天
2004-4-16 18:23 zerocold
在aix4.3上写了个服务段程序,代码大致如下:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br /><br />int DoDeal&#40;&#41;<br />{<br /> &nbsp; &nbsp; for&#40;;;&#41;<br /> &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; if &#40;accept&#40;&#41; &#60; 0&#41;<br /> &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fprintf&#40;stderr, &#34;errmsg = &#91;%d&#93;&#91;%s&#93;\n&#34;, errno, strerror&#40;errno&#41;&#41;; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return -1;<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Recv&#40;&#41;;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CloseTcp&#40;&#41;;<br /> &nbsp; &nbsp;}<br />}<br /><br />int main&#40;&#41;<br />{<br /> &nbsp; &nbsp;int i;<br /> &nbsp; &nbsp;CreateLisntenSock&#40;&#41;;<br /><br /> &nbsp; &nbsp;for&#40;i = 0; i &#60; 10; i ++&#41;<br /> &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp;if &#40;fork&#40;&#41; == 0&#41;<br /> &nbsp; &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DoDeal&#40;&#41;;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit&#40;1&#41;;<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; }<br /><br /> &nbsp; &nbsp;exit&#40;0&#41;;<br />}<br /><!--c2--></div><!--ec2--><br /><br /><br />当客户端向服务端发起请求时,服务程序的其中一个进程可以正常处理客户端请求,其他子进程由于&quot;惊群&quot;导致 accept 出错(errno为EAGAIN 或者 ENOTCONN),但理论上 accept 由于 &quot;惊群&quot; 应该会重新进入休眠状态,但在这里且出错, 不知道是不是操作系统的问题,对accept加锁就没问题了。 同样的程序(没有对accept加锁)在SCO上测试 正常,accept 没有出错(虽然存在 &quot;惊群&quot; ) 。

2007-11-26 15:36 easysword
我在基于2.6内核的slackware系统上也发现同样的问题

页: [1]
查看完整版本: 关于


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.