in reply to Automatically killing a child

Massyn:

I don't know what's going on, so this is pure speculation. But I think that tail is waiting until its input stream is closed. But with your script, tail's input stream is the terminal session's output stream (STDOUT). Thus, I think tail is waiting for your terminal session to close it's output stream before it exits.

Again, this is pure speculation....

--roboticus

Replies are listed 'Best First'.
Re^2: Automatically killing a child
by Massyn (Hermit) on May 24, 2006 at 21:45 UTC
    Hi everyone,

    This was a real interesting topic, and ++ to all for your great contributions. In the end, I removed tail from the code, and just hard coded a simple perl based tail into my code. That works, plus I don't have to fork another process.

    #!/usr/bin/perl # Known issue # If the file gets truncated, the script will not terminate # ==================================================================== +========= use IO::Handle; autoflush STDOUT; use Fcntl qw(:seek); $file = 'mylog.txt'; $started = 0; #set to 1 if you want the file to start reading from +the start of the logfile while(1) { open LOG, $file or die "$file could not be opened."; seek LOG, $pos, SEEK_SET if defined $pos; while(<LOG>) { chomp; if($started) { print "$_\n"; } } $pos = tell LOG; close LOG; sleep 1; $started = 1; } exit(0);

    Thanks!

         |\/| _. _ _  ._
    www. |  |(_|_>_>\/| | .net
                    /
    
    The more I learn the more I realise I don't know.
    - Albert Einstein