Process details

Timothy Grant tjg at exceptionalminds.com
Thu Mar 15 12:40:38 EST 2001


On Thu, Mar 15, 2001 at 09:55:43AM +0000, Quinn Dunkan wrote:
> On Mon, 12 Mar 2001 15:22:16 -0800, Timothy Grant <tjg at exceptionalminds.com>
> wrote:
> >Hi all,
> >
> >I hope everyone is enjoying there first week back after the
> >events of P9.
> >
> >I need to create a list of processes and process information. I
> >have created a class that contains much of the information in
> >/proc/'pid'/status.
> >
> >It works quite well, however, it takes about four seconds to
> >populate a list of 90 procs. This seems a bit long. Is there a
> >faster way to get ahold of the information than reading /proc?
> 
> You don't say what OS you're using, but from the sig I'm guessing Linux.  In
> Linux, /proc is the official interface.  /bin/ps and friends use it.  Try
> 'cat /proc/[0-9]*/status >/dev/null'.  If that takes less than four seconds,
> then the slowdown is likely in your code, not /proc.  On this linux machine,
> it takes a few hundredths of a second for several hundred procs.

Oh, I'm sure the slowdown is in my code. the cat mentioned
above is extremely fast...

...I just went and looked at my code and discovered the major
bottleneck--I think. The problem comes due to the fact that not
all process list all entries in the /status file. This means
that a sequential read assigning to variables won't work, so I
am actually looking for entry names in a loop.

I just added a break statement and shaved three seconds of the
time! I'm sure there is more room to optimize, but exiting my
loop after I found what I was looking for sure helps.

Sometimes I just need a second set of eyes even if they don't
even see my code. Thanks.

-- 
Stand Fast,
    tjg.

Timothy Grant                         tjg at exceptionalminds.com
Red Hat Certified Engineer            www.exceptionalminds.com
Avalon Technology Group, Inc.         <><       (503) 246-3630
>>>>>>>>>>>>>Linux, because rebooting is *NOT* normal<<<<<<<<<
>>>>This machine was last rebooted:  57 days 21:47 hours ago<<




More information about the Python-list mailing list