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.
-
Are your reading $fh in the parent process?Slaven Rezic– Slaven Rezic2013-07-17 07:25:37 +00:00Commented Jul 17, 2013 at 7:25
-
yes reading $fh in the parent process. Plz. can you suggest me any mechanism.7Srv– 7Srv2013-07-17 10:28:04 +00:00Commented Jul 17, 2013 at 10:28
-
So the child is faster in providing the data than the parent in reading and processing the data?Slaven Rezic– Slaven Rezic2013-07-17 10:45:07 +00:00Commented Jul 17, 2013 at 10:45
-
may be....not sure............7Srv– 7Srv2013-07-17 11:21:57 +00:00Commented 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...Slaven Rezic– Slaven Rezic2013-07-17 11:57:51 +00:00Commented Jul 17, 2013 at 11:57
Add a comment
|
1 Answer
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();
3 Comments
7Srv
Where I should use this statement $fh->autoflush(1); just after opening the pipe like this
codeopen($fh, '-|', "./monitor.pl"); $fh->autoflush(1); code7Srv
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.
daxim
7Srv, open a new topic with the text of your follow-up question.