Re: A (dumb?) waitpid(2) question

From: Steven Rostedt
Date: Tue Dec 21 2004 - 21:39:27 EST


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


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/