How to tell if a forked process is done?

David M. Cooke cookedm+news at physics.mcmaster.ca
Tue Sep 23 21:08:52 EDT 2003


At some point, joseph at ugcs.caltech.edu (John Lin) wrote:

> Howdy,
>
> I want to know how to tell if a forked process is done.
>
> Actually, my real question is that I want to run a shell script inside
> of a python script, and after the shell script has finished running, I
> want to do more stuff *condition* on the fact that the shell script
> has finished running, inside the same python script.
>
> The only way I can think of is to fork a process and then call the
> shell script, as in:
>   pid = os.fork()
>   if pid == 0:
>     os.execl(shellscript_name.sh, "")
> but how can I know if the shell script is finished?

Look up os.wait and os.waitpid in the Python Library Reference. Or,
for this case, use os.system().

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca




More information about the Python-list mailing list