Waiting for processes to finish under Solaris

Donn Cave donn at u.washington.edu
Tue Jul 15 14:13:02 EDT 2003


In article <3F144AB2.10703 at dadsetan.com>,
 Behrang Dadsetan <ben at dadsetan.com> wrote:

> Hi all,
> 
> please note that once I finished writing the script someone explained me 
> that there is a command pwait under Solaris... anyway it was fun to 
> write and it did not take long (while I am not a python guru..). And my 
> version is MUUUCH better :)
> 
> 
> Is there no standard interfaces to the process table? I only found 
> examples of how to do it on the win32 platform. So I parse with re the 
> output of /usr/ucb/ps...
> 
> Because I am still at the begining of learning python, I wanted to have 
> some advice here how I could have done the following code better...

Since you apparently already know the PIDs you're looking for,
it would be easier and more reliable to just kill them with 0 -

    while 1:
        time.sleep(2)
        for p in watchedforpids.keys():
            try:
                os.kill(p, 0)
            except os.error, e:
                if e.errno == errno.ESRCH:
                    del watchedforpids[p]
                else:
                    raise
            else:
                 print p, 'still alive'

Though of course that doesn't retrieve any of the other information
you get from "ps".

   Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list