psi.AttrInsufficientPrivsError: Insufficient privileges for Process.nthreads

8 views
Skip to first unread message

gsnyder2007

unread,
Mar 22, 2010, 3:59:38 PM3/22/10
to PSI - Python System Information
Here's the code:

import multiprocessing
import psi
import psi.process
import time

def do_nothing():
time.sleep(5)

proc = multiprocessing.Process(target=do_nothing)
proc.start()

p = psi.process.Process(proc.pid)
print 'Number of threads is: %s' % p.nthreads


And, when I run it as a normal user,

$ python psi_nthreads_test.py
Traceback (most recent call last):
File "psi_nthreads_test.py", line 13, in <module>
print 'Number of threads is: %s' % p.nthreads
psi.AttrInsufficientPrivsError: Insufficient privileges for
Process.nthreads

Using sudo,

$ sudo python psi_nthreads_test.py
Password:
Number of threads is: 1

Obviously, the process I launched [via Process] is 'owned' by the same
user asking for the thread count. Do I have to be "super user" or
"root" to see the thread count? This test seems to imply so, but I'm
hoping there is a finer-grained approach which doesn't require that
level of privileges because I want to use PSI within a suite of unit
tests that should not be run as "super user".

I checked the Wiki and 'Google' but couldn't find what I must be
missing. I know I could read through the code and try to figure it out
but I'm hoping I'm missing something simple that will be easy to point
out.

Any hints would be greatly appreciated.

Chris Miles

unread,
Mar 22, 2010, 7:04:40 PM3/22/10
to psi-d...@googlegroups.com, Chris Miles

Hi,

You don't say what system you are running on but I assume OS X as I get the same result on a Mac. Some process attributes are not able to be read from outside the process, even by the same owner, except by the super user. That is the case on some systems, anyway. The above code works fine on Linux, for example.

You will notice that /bin/ps and /usr/bin/top on OS X are both setuid root, to give them privileges to read this information about all processes. On Linux that is not the case, so it just comes down to each system's process security model.

Cheers,
Chris

gsnyder2007

unread,
Mar 23, 2010, 8:40:28 AM3/23/10
to PSI - Python System Information
Thanks Chris. Yes, Mac OS X 10.5.8 for future reference.
Reply all
Reply to author
Forward
0 new messages