1

I am having two separate scripts and I am to trying initiate the execution of one script(child process) from another script(parent process) using pipe mechanism such as open($fh, '-|', "./monitor.pl") here monitor.pl is the child process such that both of them executes asynchronously and at the same time. The output of the commands placed inside the while loop of the child process are written to the pipe handle continuously for that reason the buffer is getting filled up. So please suggest me the mechanism and appropriate location to flush the buffer such that the child process never hangs up as the buffer fills up.

5
  • Are your reading $fh in the parent process? Commented Jul 17, 2013 at 7:25
  • yes reading $fh in the parent process. Plz. can you suggest me any mechanism. Commented Jul 17, 2013 at 10:28
  • So the child is faster in providing the data than the parent in reading and processing the data? Commented Jul 17, 2013 at 10:45
  • may be....not sure............ Commented Jul 17, 2013 at 11:21
  • Well, if this is the case, then you need something between parent and child which can buffer child's output. Of course, this works only if there are some periods where child is not producing less output... Commented Jul 17, 2013 at 11:57

1 Answer 1

1

See IO::Handle.

Automatically flush after writing:

$fh->autoflush(1);

Flush manually:

$fh->flush;

On Perl versions lower than 5.14 you also need to load the IO::Handle module:

use IO::Handle qw();
Sign up to request clarification or add additional context in comments.

3 Comments

Where I should use this statement $fh->autoflush(1); just after opening the pipe like this codeopen($fh, '-|', "./monitor.pl"); $fh->autoflush(1); code
The above mechanism is not working in my script scenario. The execution of the child process monitor.pl is initiated by using this pipe mechanism open($fh, '-|', "./monitor.pl") from a parent process. The parent process may execute for several hours and the child process must also execute as long as the parent process executes asynchronously but the child process hangs up after 50 mins. I want that the child process should write to the pipe handle as long as the parent process executes which may 2-3 hours. Plz. suggest me any mechanism which can help me. Thanks in advance.
7Srv, open a new topic with the text of your follow-up question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.