From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sam Steingold Newsgroups: gmane.emacs.devel Subject: Re: busyloop in sigchld_handler Date: Mon, 12 Mar 2007 14:57:56 -0400 Message-ID: <45F5A2B4.7090301@gnu.org> References: <45F59395.4010708@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1173725900 13641 80.91.229.12 (12 Mar 2007 18:58:20 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 12 Mar 2007 18:58:20 +0000 (UTC) Cc: emacs-devel@gnu.org To: Andreas Schwab Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 12 19:58:13 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HQpil-0001FU-KK for ged-emacs-devel@m.gmane.org; Mon, 12 Mar 2007 19:58:11 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HQpjS-0003cp-06 for ged-emacs-devel@m.gmane.org; Mon, 12 Mar 2007 13:58:54 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HQpjG-0003cS-6U for emacs-devel@gnu.org; Mon, 12 Mar 2007 14:58:42 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HQpjE-0003cD-LT for emacs-devel@gnu.org; Mon, 12 Mar 2007 14:58:41 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HQpjE-0003cA-FE for emacs-devel@gnu.org; Mon, 12 Mar 2007 13:58:40 -0500 Original-Received: from www.janestcapital.com ([66.155.124.107] helo=smtp.janestcapital.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HQpiX-0006Yz-CQ for emacs-devel@gnu.org; Mon, 12 Mar 2007 14:57:57 -0400 Original-Received: from [192.168.250.217] [209.213.205.130] by janestcapital.com with ESMTP (SMTPD-9.10) id A2B40850; Mon, 12 Mar 2007 14:57:56 -0400 User-Agent: Thunderbird 1.5.0.8 (X11/20061107) In-Reply-To: X-detected-kernel: Windows 2000 SP4, XP SP1+ X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:67805 Archived-At: Andreas Schwab wrote: > Sam Steingold writes: > >> Andreas Schwab wrote: >>> Sam Steingold writes: >>> >>>> wait3 is a system call, which, when invoked in a loop, prevents the >>>> kernel from doing anything else (in this case, sending SIGCHLD to >>>> emacs). sleep allows the kernel some time to pass the signal. >>> I don't find this explanation convincing at all. Since the system call is >>> made _inside_ the signal handler, the signal is actually blocked here, so >>> it cannot be delivered anyway. >> yes, you are right. >> what I should have said was that by making a system call in a busyloop, >> emacs prevents the kernel from doing what it needs to do to the the child >> so that wait3 will succeed. > > What does the kernel have to do? The EINTR error will only happen when > the system call was interrupted _and_ a signal handler was called. I don't know the details, but the kernel obviously has to do SOMETHING when the child process terminates: it has to notice the state change so that wait3 in emacs will return "yes, the child is dead" instead of "nothing for you yet". The busyloop prevents the kernel from doing anything for some time. Now, it might be better to remove the WNOHANG option instead (except that signal handlers are not supposed to hang), or use usleep(10000) instead of sleep(1), but the busyloop is what has to be fixed. Please also note that I am not in any way an expert in kernel matters. Sam.