llancet has asked for the wisdom of the Perl Monks concerning the following question:

I want to use them, because according to the document, SIGRTs can be queued while multiple signals come. However, the program just exit:
#!/usr/bin/perl use common::sense; use Glib qw/TRUE FALSE/; $SIG{'SIGRTMIN+5'} = \&on_sig; my $loop = Glib::MainLoop->new( 'default', FALSE ); $loop->run; sub on_sig { my $sig = shift; say "somebody told me $sig"; }
send him a min+5
$ ./ & [2] 3305 $ kill -s SIGRTMIN+5 3305 $ [2]+ Real-time signal 5 ./ $

Replies are listed 'Best First'.
Re: Unix real time signals
by zwon (Abbot) on Oct 16, 2010 at 09:32 UTC

    The following code should do the trick:

    use strict; use warnings; use Config; use List::MoreUtils qw(firstidx); my @signals = split / /, $Config{sig_name}; my $rtmin = firstidx { $_ eq 'RTMIN' } @signals; my $rt5name = $signals[ $rtmin + 5 ]; print "They call it $rt5name\n"; $SIG{$rt5name} = sub { warn "caught it!\n" }; sleep 10 while 42;
Re: Unix real time signals
by lidden (Curate) on Oct 16, 2010 at 03:15 UTC
    Try without the SIG part. I.e: $SIG{'RTMIN+5'} = \&on_sig;
      If you "use warnings" you'll see:

      No such signal: SIGSIGRTMIN+5 at line 5.

      I can't get anything to work with the +5 stuff, but this code works:

      #!/usr/bin/perl use strict; use warnings; $SIG{'RTMIN'} = \&on_sig; print $$, "\n"; while (1) { sleep 1; print ".\n"; } sub on_sig { my $sig = shift; print "somebody told me $sig"; }

      When I send it a signal like this:

      $ kill -s SIGRTMIN 763

      I get:

      somebody told me RTMIN.


      (Wow, I've been gone too long. This was supposed to be a reply to the original question!)

        I thought first 3 RT signals are conserved by something. I forgot where I seen that...