mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "usvyatsky, ilya" <usvyatsky_ilya@emc.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: A (dumb?) waitpid(2) question
Date: Tue, 21 Dec 2004 21:38:11 -0500	[thread overview]
Message-ID: <1103683091.14114.8.camel@localhost.localdomain> (raw)
In-Reply-To: <FA2F59D0E55B4B4892EA076FF8704F550846C103@srgraham.eng.emc.com>

On Tue, 2004-12-21 at 19:26 -0500, usvyatsky, ilya wrote:
> As dumb as it seems, I am seing a weird behavior on my RH3.0 box
> (2.4.21-20.Elsmp kernel).
> 
> It looks like (contrary to the man page and POSIX .1) waitpid(2) does not
> return upon a SIGALRM.
> 
> I am porting an old piece of Solaris userland code (stripped from all useful
> functionality):

I changed your code with the following:

@@ -25,11 +25,15 @@
     if (child_pid) {
         /* parent */
         int status = 0, timeout = 1;
+       struct sigaction sa;
+       sa.sa_handler = sig_handler;
+       sa.sa_flags = SA_NOMASK;

         do {
             printf("Parent: setting an alarm for %d seconds\n", timeout);

-            signal(SIGALRM, sig_handler);
+           sigaction(SIGALRM, &sa,NULL);
+//            signal(SIGALRM, sig_handler);
             alarm(timeout);

             printf("Parent: waiting for a child %d\n", child_pid);


And got the following result:

$ ./alarmit
Child:  sleeping for 6 seconds
Parent: setting an alarm for 1 seconds
Parent: waiting for a child 25926
Alarm!!!
Parent: wait was interrupted by a signalParent: setting an alarm for 1 seconds
Parent: waiting for a child -1
Alarm!!!
Parent: wait was interrupted by a signalParent: setting an alarm for 1 seconds
Parent: waiting for a child -1
Alarm!!!
Parent: wait was interrupted by a signalParent: setting an alarm for 1 seconds
Parent: waiting for a child -1
Alarm!!!
Parent: wait was interrupted by a signalParent: setting an alarm for 1 seconds
Parent: waiting for a child -1
Alarm!!!
Parent: wait was interrupted by a signalParent: setting an alarm for 1 seconds
Parent: waiting for a child -1
Child:  exiting
Parent: child 25926 terminated normally with status 0


> Is it a bug or a feature?

I guess it's a feature, and the default signal function must have
SA_RESTART set.

> Any suggestions would be greatly appreciated...
> 

Use sigaction instead of signal.


-- Steve



  reply	other threads:[~2004-12-22  2:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-22  0:26 usvyatsky, ilya
2004-12-22  2:38 ` Steven Rostedt [this message]
2004-12-22  2:52 usvyatsky, ilya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1103683091.14114.8.camel@localhost.localdomain \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=usvyatsky_ilya@emc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®