Hello Ravi,

what I would do is use signals to give a nudge to the long running process...

I have included a print statement (you can make that to log one single entry in a logfile) OR, also fancy, modify the name of the script $0 directly, hence, you get the information through ps -ef (used by some programs). There are more ways, like named pipes, etc.

#!/usr/bin/perl my $SHOUT = 0; $SIG{USR1} = sub { ++$SHOUT; }; my $PROGRAM = $0; print "$PROGRAM started with pid $$\n"; my $counter = 0; while(1) { $counter++; if($SHOUT){ print "$0 says: $counter \n"; $0 = $PROGRAM . " counter=$counter"; $SHOUT = 0; } sleep 1; }

The nudge is given with a kill -USR1 $PID

Update:

The normal way is to have a second program that asks for ETA and status. This second program send the signal, then both programs then initiate a temporal TCP connection to send/receive the information. But from what I read in your post, you want to keep it simple. The other way is to only update your linenumber logfile each 10 seconds. you will need $NEXTUPDATE = time()+1000*10 and do compares if(time()>$NEXTUPDATE) This will use much less IO than logging each line.

edit2: added missing my's. And Do'h, suggesting same things as peers... sorry for that.

*important note*: Do not use IO in signals. Your script could coredump if you open files and such. Do the work outside.


In reply to Re: Want to know Line number of the input file by FreeBeerReekingMonk
in thread Want to know Line number of the input file by ravi45722

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.