in reply to Suggestions on differentiating child processes
Then your work code can log its progress:use File::Temp; use constant STATUS_DIR => '/tmp/status-dir'; { my $fh; # hidden from outer code # status is logged only when you have created # the status dir by hand; this lets you turn off # logging by deleting the status dir if ( -d STATUS_DIR ) { $fh = new File::Temp( template => "$$-XXXXXX", dir => STATUS_DIR, suffix => ".txt", unlink => 1 ) or die "can't open temp file: $!"; $fh->autoflush(1); } sub log_status { print $fh "$$ - ", scalar localtime, " - ", @_, "\n" if $fh; } sub close_status { $fh->close if $fh; } }
If a worker bee gets hung up, you can observe its status from the log that corresponds to its pid. For example, I justed fired one up with pid 14416. Let's see what it is doing:# here is the meat of our worker code log_status("worker starting; config=blah..."); # ... work ... log_status("worker starting stage two"); # ... more work ... log_status("worker starting stage three"); sleep 30; # it's a long one # finally! whew, that was hard work :) log_status("worker exiting"); close_status();
Ah, it's that darn stage-three work! It always takes too long.$ cat /tmp/status-dir/14416-UXL0uq.txt 14416 - Fri Nov 12 12:40:06 2004 - worker starting; config=blah... 14416 - Fri Nov 12 12:40:06 2004 - worker starting stage two 14416 - Fri Nov 12 12:40:06 2004 - worker starting stage three
Also, since the log files are automatically deleted upon completion, you can see what tasks are still running by listing the contents of the status-log directory.
Cheers,
Tom
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Suggestions on differentiating child processes
by gnu@perl (Pilgrim) on Nov 12, 2004 at 18:04 UTC |