nikademus79 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Only the pid of the processes are returned in Mac OS X 10.7 Lion (preview 4) #173

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Execute the following code:
import psutil

for un in psutil.process_iter():
  try:
    print un
  except:
    pass

What is the expected output? What do you see instead?
- You get a list of all the processes in the system in this format: 
psutil.Process(<all process info>)

- You get a list of all the processes in the system only with the pid: 
psutil.Process(pid=15) The only process that displays more information is: 
psutil.Process(pid=0, name='kernel_task')

What version of psutil are you using? What Python version?
- psutil 0.21
- python 2.7

On what operating system? Is it 32bit or 64bit version?
Mac OS X 10.7 Lion (preview 4) 64 bits

Please provide any additional information below.
If you, for example, replace in the code above "print un" with "print un.name", 
you will only get: kernel_task

Original issue reported on code.google.com by fdv...@gmail.com on 14 Jun 2011 at 8:20

GoogleCodeExporter commented 8 years ago
Please provide some more info.
Do you get AccessDenied exceptions?
What if you run:

>>> import psutil, os
>>> p = psutil.Process(os.getpid())
>>> p.name
...
>>> p.cmdline
...
[ other method calls here ]

Does it make any difference if run as root or limited user?

Original comment by g.rodola on 14 Jun 2011 at 8:24

GoogleCodeExporter commented 8 years ago
- I get an AccessDenied exception with p.name, p.exe, p.cmdline and p.path
- I get nothing with p.pid, p.ppid and p.parent (I mean, no exception and no 
result).
- Same result if I execute: "python a.py" or "sudo python a.py"

Original comment by fdv...@gmail.com on 14 Jun 2011 at 8:39

GoogleCodeExporter commented 8 years ago
Then I guess OSX Lion is even more restricted than previous OSX versions on 
which we already experienced serious permission limitations (see issue 108). 
I'll leave this one to Jay but my guess is that we can't do much about it other 
than providing instructions on how to run psutil via setuid, assuming it is a 
valid workaround in the first place.

Original comment by g.rodola on 14 Jun 2011 at 8:55

GoogleCodeExporter commented 8 years ago
I don't have access to a 10.7 machine so I have no way to debug this presently. 
It sounds like the kernel structures or syscalls may have changed again in 
10.7, or it's possible there is a new security model as Giampaolo had 
suggested. The AccessDenied results would seem to indicate we're not being 
allowed to read process information but I'm not sure why there would be no 
result for pid, ppid, cmdline and path.

Did you run the suggested code exactly as shown, with "p = 
psutil.Process(os.getpid())" ? It seems strange that we would be prevented from 
reading process information for the calling process, even accounting for some 
new security restriction.

-Jay

Original comment by jlo...@gmail.com on 14 Jun 2011 at 11:40

GoogleCodeExporter commented 8 years ago
Yes, I executed exactly "p = psutil.Process(os.getpid())". As far as I know, 
10.7 has got changes in the permissions system.

Original comment by fdv...@gmail.com on 14 Jun 2011 at 1:50

GoogleCodeExporter commented 8 years ago
I get this error on 10.6 as well, both as root and as a normal user.

Original comment by turbina...@gmail.com on 18 Sep 2011 at 6:45

GoogleCodeExporter commented 8 years ago
The example given in this issue does not give us any information to work with 
since it's skipping/passing all the exceptions. I think this is the same as 
Issue 207 so it would be worth trying the same thing I suggested there. Try the 
below script as root - e.g. save to psutil_proc_iter.py and run as "sudo python 
psutil_proc_iter.py" 

import psutil

for proc in psutil.process_iter():
    try:
        print proc
    except psutil.AccessDenied:
        print "AccessDenied exception for PID %s" % (proc.pid)
    except Exception,e:
        print "Other exception: %s" % (e)

Let us know the results so we can narrow this down. 

Original comment by jlo...@gmail.com on 18 Sep 2011 at 6:53

GoogleCodeExporter commented 8 years ago
I get the following on OS X 1.7.3

$ sudo python psutil_proc_iter.py
Password:
psutil.Process(pid=65030, name='Python')
psutil.Process(pid=65029, name='auditd')
psutil.Process(pid=65028, name='sudo')
psutil.Process(pid=65027, name='Python')
psutil.Process(pid=64962, name='bash')
psutil.Process(pid=64961, name='login')
...

and without sudo:

$ python psutil_proc_iter.py
psutil.Process(pid=65094, name='Python')
psutil.Process(pid=65093, name='sleep')
psutil.Process(pid=64962, name='bash')
psutil.Process(pid=64961)
psutil.Process(pid=64658, name='bash')
psutil.Process(pid=64657)
...

It seems that only the names of those processes show up which are owned by the 
user executing the python program.

Original comment by ske...@googlemail.com on 5 Apr 2012 at 2:26

GoogleCodeExporter commented 8 years ago
This should have been fixed in issue 297.
Closing it out.

Original comment by g.rodola on 17 Aug 2012 at 6:14