[Jax.PM] child proc output

J Proctor jproctor at marlboro.edu
Wed Oct 9 09:11:38 CDT 2002


> Sometimes my file gets messed up despite the lock, and I want to see
> what's going on. I have a bunch of print statements but I don't see
> them. The fork executes a subroutine and exits, it's not a fork and
> exec. How do I see the output from the kid when I run the parent script
> manually?

I tried a simple test of printing from within a forked subroutine:

while (<>)
    {
    print "got some stdin ";
    if (not (time % 5))
        {
        if (!fork)
            {
            zap();
            exit;
            }
        }
    print "and chewed on it.\n"
    }

sub zap
    {
    print "ZAP! \n";
    }

and I ran it from the command line.  Type some stuff on stdin and it'll
tell you it got it, unless the current time is divisible by 5, when it'll
print ZAP! in the middle.  It works beatifully on my system, anyway.

Options:  Try printing to STDERR from the forked sub.  Try $|=1 (and
don't forget to check that you're debug-printing newlines).  Try ditching
the fork and inlining the counter file update at the same interval.

In the bigger picture, it's difficult to imagine what could corrupt the
counter file under those circumstances, unless (a) the time interval is so
short it's stepping on itself, or (b) you've got multiple things trying to
use the data, and your system doesn't do file locking in any sane way.
That would be most of them, by the way.  If you have multiple processes
that need to get at them, you might be better off stuffing the numbers in
a database somewhere.


j




More information about the Jacksonville-pm mailing list