[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Craig Markwardt wrote:
> marc <email@example.com> writes:
> > I want to spawn under UNIX one program many times (multiprocessor
> > machine). So I could sent it into the background using the UNIT keyword,
> > but how can I determine when the program finishes?
> > I run some basic tests and it seems that IDL leaves the unit open.
> > Is there a way or have I (ab)use the filesystem for this (via
> > lockfiles)?
> A clarification is in order. SPAWN with the UNIT keyword does *not*
> run the process in the background. The unit stays open because IDL
> attaches the output of the process to the unit, and IDL is waiting for
> you to read the output.
> You can run the process in the background by adding '&' like you
> normally would. Then be sure that you redirect the output and CLOSE
> the unit.
> To find out whether a background process is finished is difficult.
> Usually it's just easiest to write a flag to a temporary file when the
> job is done, and have IDL periodically monitor that file for changes.
> One can probably do it with the unix system call waitpid(), but you
> that would require compiling a DLM, not for the faint of heart.
> Good luck,
The & at the end does only work in shell mode. Wiht SPAWN,/NOSHELL,...
you get an error message because the process treats it as an option. but
with SPAWN,/NOSHELL,UNIT=u,... IDL returns immediatly back to the
command line (also without /NOSHELL), or continues execution (at least
under Solaris and Linux, IDL 5.2).
But even then fstat(u) doesn't tell you anything about the process
status. Al least you can kill the process with FREE_LUN,u .
Right now I spawn every some seconds a 'ps' command and compare the
pid's (from PID parameter) to see if the process is already running.
But this 'ps' bothers, since the behaviour is little different between
Solaris and Linux.