develooper Front page | perl.perl5.porters | Postings from January 2001

Re: "Safe Signals" - please try this test

Thread Previous | Thread Next
From:
___cliff rayman___
Date:
January 17, 2001 14:42
Subject:
Re: "Safe Signals" - please try this test
Message ID:
3A6620A8.821D3320@spamless.genwax.com
$ ./a.out
wait pend=1 status=0
$ uname -a
dgux t4 R4.11MU04 generic AViiON PentiumPro


nick@ing-simmons.net wrote:

> I am playing with safe signals again.
>
> With this scheme C code just sets a pending flag, and then perl level
> handler is called next time round the runops loop.
>
> I have a half remembered worry. I seem to recall some system where
> if the SIGCHLD signal handlder did not do a wait() of some kind
> then when it returned SIGCHLD was posted again, and again, and ...
>
> The attached program attempts to test for this case.
> Will those of you with various UNIXes try it please?
> (Linux+glibc is okay).
>
> If I have remembered correctly, then on such awkward systems we need
> to do a wait() in the handler and save status somewhere. Which is a
> pain as one does not know (in the general case) the pid in advance
> to pre-allocate storage.
>
> --
> Nick Ing-Simmons
>
>                                                   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> #define PERLIO_NOT_STDIO 0
> #include "EXTERN.h"
> #include "perl.h"
>
> #if 0
>
> #include <stdio.h>
> #include <sys/time.h>
> #include <sys/types.h>
> #include <sys/wait.h>
> #include <signal.h>
> #include <unistd.h>
> #include <errno.h>
>
> #endif
>
> int pending;
>
> #ifndef SIGCHLD
> #define SIGCHLD SIGCLD
> #endif
>
> void
> catch(int sig)
> {
>  pending++;
>  if (pending > 1)
>   {
>    signal(SIGCHLD,SIG_DFL);
>   }
> }
>
> int
> main(int argc, char *argv[])
> {
>  int code;
>  int pid;
>  signal(SIGCHLD,&catch);
>  pid = fork();
>  if (pid == 0)
>   {
>    sleep(1);
>    exit(0);
>   }
>  else
>   {
>    int pid2;
>    int status;
>    while (!pending)
>     {
>      struct timeval t;
>      t.tv_usec = 100000;
>      t.tv_sec  = 0;
>      code = select(0,NULL,NULL,NULL,&t);
>      if (code && errno != EINTR)
>       {
>        perror("select");
>       }
>     }
>    pid2 = wait(&status);
>    fprintf(stderr,"wait pend=%d status=%d\n",pending,status);
>   }
> }

--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About