Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Apr 2001 16:56:37 -0500
From:      Lucas Bergman <lucas@slb.to>
To:        Arcady Genkin <a.genkin@utoronto.ca>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: [OT] Reinstalling signal handler inside signal handler
Message-ID:  <20010405165637.C18827@billygoat.slb.to>
In-Reply-To: <87vgojc9gc.fsf@tea.thpoon.com>; from a.genkin@utoronto.ca on Thu, Apr 05, 2001 at 05:39:47PM -0400
References:  <87d7ardw5s.fsf@tea.thpoon.com> <20010405161123.A18827@billygoat.slb.to> <87vgojc9gc.fsf@tea.thpoon.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> > Signals on "traditional" systems (V7, System V) were reset to
> > their default behavior after they were raised, so the signal
> > handler had to reinstall itself if it was to persist.  BSD changed
> > that; you have to deliberately reset a signal's behavior (excuse
> > the split infinitive).  Linux actually follows the old semantics,
> > but you can include <bsd/signal.h> instead of <signal.h> (or call
> > __bsd_signal() instead of signal()) to get the BSD semantics.
> 
> Lucas, thanks for your answer.  For the record, it seems like Linux
> does use the *BSD* sematics that you describe above.

I'll be damned.  The following code demonstrates that you're right:

  % uname -a
  Linux apu 2.2.16 #15 Thu Feb 15 11:12:47 CST 2001 i686 unknown
  % cat sig.c
  #include <stdio.h>
  #include <signal.h>
  #include <unistd.h>
  
  void f(int sig) { printf("signal handled\n"); }
  
  int main()
  {
    if (signal(SIGHUP, f) == SIG_ERR)
      {
        fprintf(stderr, "Blargh!\n");
        exit(1);
      }
    for (;;) sleep(1);
    return 0;
  }
  % gcc -Wall -g -o sig sig.c
  % ./sig &
  [1] 30547
  % kill -HUP 30547
  signal handled
  % kill -HUP 30547
  signal handled

I'm not really a Linux person, so I was just quoting the man page,
which I guess is out of date.

Cheers,
Lucas

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010405165637.C18827>