Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 700103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:27:37+00:00 2026-05-14T03:27:37+00:00

Is there any POSIX signals that I could utilize in my Perl program to

  • 0

Is there any POSIX signals that I could utilize in my Perl program to create event-driven programming? Currently, I have multi-process program that is able to cross communicate but my parent thread is only able to listen to listen at one child at a time.

foreach (@proc) {
  sysread(${$_}{'read'}, my $line, 100); #problem here
  chomp($line);
  print "Parent hears: $line\n";
}

The problem is that the parent sits in a continual wait state until it receives it a signal from the first child before it can continue on. I am relying on ‘pipe’ for my intercommunication.

My current solution is very similar to: How can I use `pipe` to facilitate interprocess communication in Perl?

If possible I would like to rely on a $SIG{…} event or any non-CPAN solution.

Update:

As Jonathan Leffler mentioned, kill can be used to send a signal:

kill USR1 => $$; # send myself a SIGUSR1

My solution will be to send a USR1 signal to my child process. This event tells the parent to listen to the particular child.

child:

kill USR1 => $parentPID if($customEvent);
syswrite($parentPipe, $msg, $buffer);
#select $parentPipe; print $parentPipe $msg;

parent:

$SIG{USR1} = {
   #get child pid?
   sysread($array[$pid]{'childPipe'}, $msg, $buffer);   
};
  1. But how do I get my the source/child pid that signaled the parent?
    Have the child Identify itself in its message.
  2. What happens if two children signal USR1 at the same time?

Update 2: Solution

I went with a select that utilized a vector approach for non-blocking IO.
For those that come across this thread check out: Perl Cookbook: 7.22. Reading from Many Filehandles Without Blocking as it covers both the vector way and the IO::Select module. I understand the IO::Select module would have been more elegant, but I was more interested in learning new mechanics of Perl. Thank you everyone for your help.

Exert:

$rin = '';
# repeat next line for all filehandles to poll
vec($rin, fileno(FH1), 1) = 1;
vec($rin, fileno(FH2), 1) = 1;
vec($rin, fileno(FH3), 1) = 1;

$nfound = select($rout=$rin, undef, undef, 0);
if ($nfound) {
  # input waiting on one or more of those 3 filehandles
  if (vec($rout,fileno(FH1),1)) { 
      # do something with FH1
  }
  if (vec($rout,fileno(FH2),1)) {
      # do something with FH2
  }
  if (vec($rout,fileno(FH3),1)) {
      # do something with FH3
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:27:37+00:00Added an answer on May 14, 2026 at 3:27 am

    You can use select to monitor communications channels (note: if you are on Win32 select can only be used on a socket).

    So you can use code like this:

    use IO::Select;
    use IO::Handle;
    
    ...
    
    $_->blocking(0) for @handles;
    
    while( 1 ) {
        my $s = IO::Select->new( @handles );
    
        for my $h ( $s->can_read( 1 ) ) {
    
            my $data = read_handle($h);
            process_handle_data( $data );
        }
    
    }
    
    sub read_handle {
        my $h = shift;
    
        my $got = '';
    
        1 while read( $h, $got, 1024, length $got );
    
        return $got;
    }
    

    Take a look at the UDP example in perlipc. It uses the select built-in. I prefer the core IO::Select module to the select built-in, it’s much easier to read.

    Update: You really should consider using an event framework like POE, Event or Coro. There’s a pretty good list of options in this perlmonks thread. Don’t fear CPAN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that forks and creates three POSIX pipes for the child's
Is there any free or commercial component written in .NET (no COM interop) that
Is there any way to check the granularity of gettimeofday() function provided by POSIX?
I have been learning thread programming in Java, where there are are sophisticated APIs
Is there any way to check whether a file is locked without using a
Is there any query which can return me the number of revisions made to
Is there any efficiency difference in an explicit vs implicit inner join? For example:
Is there any way to capture the MouseDown even from the .NET 2.0 TextBox
Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and
Is there any known way of listing the WMI classes and their properties available

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.