in reply to Want to know Line number of the input file
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.
|
|---|