Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

process monitor

Status
Not open for further replies.

codemut

Programmer
Feb 29, 2008
26
0
0
US
I've got a gawk script that controls other gawk scripts, one of which displays overall progress on the command line. While a progress display is simple to implement given iterations within a given script, I wish to monitor the progress of the controlling script via process id and to add an estimate of processing time remaining. Despite attempts with processes started in the background, the monitor script prevents the main script from moving to its next procedure or ending. Perhaps using gawk for these tasks adds a redundant layer of complexity on top of the shell. I humbly seek your insight.
 
Very difficult to guess what's going on here without seeing some sample code...?

Annihilannic.
 
The main script:

#!/usr/bin/gawk -f
BEGIN {

cmd1 = "./meterScript" ### output to terminal
print cmd1 | "bash"
close(cmd1)

### script3 below must wait for script2
cmd2 = "./script2; wait" ### output to a file
print cmd2 | "bash"
close(cmd2)

cmd3 = "./script3" ### output to a file
print cmd3 | "bash"
close(cmd3)
}

The meterScript...
... maybe the exit status of main's last script should figure here in meterScript?:

#!/usr/bin/gawk -f

BEGIN {
ORS = ""
OFS = ""
$PRID = PROCINFO["ppid"]

while (1) {

cmd = "ps -ef | grep "$PRID" | grep -vq grep"
("$?" | getline DONE)

if (! DONE) {
for(k = 1; k <= 20; k++) {
print "\t["
for (i = 1; i <= k; i++) {
print "="
}
print ">"
for(j = 1; j <= 20 - k; j++) {
print "."
}
print "]\r"
system("sleep 1")
}
}
else {
break
}
}
print "\nDone\n"
system("")
}
 
I agree that gawk probably complicates this unnecessarily. Also you are not actually starting any of those processes in the background as it stands. gawk is probably fine for the actual process meter part, but I'd stick to plain old shell for the main script. How does your meter script measure how much progress has been made by the other process?

Annihilannic.
 
Previously, the individual scripts called the meter script directly, an incremented counter sent as an argument for generating the percent of total complete. As that became cumbersome, a single call to the meter became the goal. If/when accomplished, marking intervals using strftime() between called scripts, and using this as an argument with the meter, may afford estimated and printing expected finish time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top