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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

monitor background process

Status
Not open for further replies.

clkanski

Technical User
Jan 13, 2005
5
US
I want to launch a process is the background and monitor it in a polling routine. The process is variable in length and may or may not be killed by the user. Is there a way to assign a variable to the stdout? Can I "see" the process ID? Here is what I was thinking. Is this possible?

exec $somescript &

while {!$done} {
#monitor the process of $somescript
#possibley with a vwait statement?
set done 1
}

#process output from $somescript
 
Sure. Use threads for monitored proc + fork() for
the process and some passed variables.
You can go lower than this, but I'm getting the
impression that you don't want to.
C is it. Tcl would work as well except you would have
to parse a ps - ? and hope it's right.

The shell has been used for stuff like this for years
also. The code is often horribly lame, but works.
 
I was hoping to stay within tcl. This is art of an script, that for the most part, is already written and works pretty good. I use to wait till the process was done, but more and more often, the process got killed by the user of the machine. So, the script died, and I had to go clean up manually. I would like the polling script to tell the difference of a natuaral stop and a forced stop. I don't know which tcl commands allow for this branch/unite mechanism.
 
You need to include signal handlers. Catch the
termination and cleanup. That's the easiest and best
way IMHO.
TclX and Expect both have the desired
capability. For windows, have a look at
twapi, which is very cool too.


HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top