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 241515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:45:36+00:00 2026-05-11T20:45:36+00:00

Recently I had a problem using (pipe |-) when I wanted to communicate between

  • 0

Recently I had a problem using (pipe |-) when I wanted to communicate between two processes.
Basically, the child process couldn’t process STDIN as fast as it was filled up by parent. This caused parent to wait until STDIN was free and made it run slow.

How big can STDIN be and is it possible to modify it. If yes, what is the best practice size?

Here is some code sample to show what I mean:

if ($child_pid = open($child, "|-"))
{
    $child->autoflush(1);

    # PARENT process
    while (1)
    {

             # Read packet from socket save in $packet
             process_packet($packet);

             # forward packet to child
             print $child $packet;
     }
}
else
{
     die "Cannot fork: $!" unless defined $child_pid;
     # CHILD process
     my $line;  

     while($line = <STDIN>)
     {
         chomp $line;
         another_process_packet($line);
     }
}

In this sample another_process_packet slower than process_packet. The reason I write the code like this is, I want to use same data comes from socket and actually get it once.

Thanks in advance.

  • 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-11T20:45:36+00:00Added an answer on May 11, 2026 at 8:45 pm

    You can of course buffer in the parent process, and only write to the child when the child’s fd is writable (i.e., writing won’t block). You can do this yourself with the right args to syswrite, or use an event loop:

    use AnyEvent;
    use AnyEvent::Handle;
    
    # make child, assume you write to it via $fh
    
    my $done = AnyEvent->condvar;
    my $h = AnyEvent::Handle->new( fh => $fh );
    
    while( you do stuff ){
        my $data = ...;
        $h->push_write($data); # this will never block
    }
    
    $h->on_drain(sub { $done->send });
    $done->wait; # now you block, waiting for all writes to actually complete
    

    Edit: This used to be untested, but I tested it, and it works. (I used perl -ne "sleep 1; print $_" as the slow child.) Writes proceed during the while loop, if possible, but never block the loop. At the end, you actually block until all the writes have completed.

    My test scripts are on gist.github: http://gist.github.com/126488

    You can see how the child blocks the blocking loop, but how it doesn’t block the non-blocking loop. Obvious when you put it that way 😉

    (Finally, as a general rule of thumb; if you are interacting with the network or with other processes, you should probably be using an event loop.)

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

Sidebar

Ask A Question

Stats

  • Questions 147k
  • Answers 147k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Full commented source to a state-machine based approval workflow comes… May 12, 2026 at 9:08 am
  • Editorial Team
    Editorial Team added an answer There happens to be a bunch of functions available in… May 12, 2026 at 9:08 am
  • Editorial Team
    Editorial Team added an answer Javascript should be this $(document).ready(function(){ $("div").hover(function() { $(this).css('background-color' , 'yellow');… May 12, 2026 at 9:08 am

Related Questions

I recently realized that some countries display floating point numbers with different comma/period notation.
I recently had a problem with the Issue Tracker starter kit that seemed to
I've had a serious issue with my Visual Studio 2008 setup. I receive the
Recently, I was challenged in a recent interview with a string manipulation problem and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.