Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil Does Not Return path or cmdline on os x #106

Closed
giampaolo opened this issue May 23, 2014 · 8 comments
Closed

psutil Does Not Return path or cmdline on os x #106

giampaolo opened this issue May 23, 2014 · 8 comments

Comments

@giampaolo
Copy link
Owner

From she...@gmail.com on August 26, 2010 22:46:22

sheats-2:~ sheats$ ps aux | grep 41727
root     41727   0.5  6.3  4686100 531628 s001  S+   Wed10AM  
23:24.37 ./servers/mongo/bin/mongod --rest -vvvvv 
--dbpath=./servers/dbs/mongo
sheats   66301   0.0  0.0  2435036    528 s000  S+    3:42PM   0:00.00 grep 41727
sheats-2:~ sheats$ python
Python 2.6.4 ( r264 :75706, Dec 25 2009, 08:52:16) 
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.__version__
'0.2.0'
>>> p = psutil.Process(41727)
>>> p.name
'mongod'
>>> p.cmdline
[]
>>> p.path
''
>>> 


Shouldn't there be values returned?  They show in the ps command.

Original issue: http://code.google.com/p/psutil/issues/detail?id=106

@giampaolo giampaolo self-assigned this May 23, 2014
@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on August 26, 2010 15:04:50

Psutil needs to be invoked as root in order for it to have access to 
any of the process information for any processes other than the 
current user's own processes. This is due to a security restriction 
inherent to OS X that prevents processes from querying each other's 
information unless the caller is root or part of the process access 
group. We're able to get the process name, but cmdline, memory info 
etc require more access (path builds off of the cmdline so it's 
usually empty if the cmdline isn't available).

You'll notice that tools like 'ps' and 'top' are setuid which is why 
they can access other process's information. The best workaround for 
now is run your script with sudo if you need to access other processes' info.

Status: Accepted

@giampaolo
Copy link
Owner Author

From she...@gmail.com on August 27, 2010 09:02:11

I tried sudo and no luck.  Here's my test script:

import psutil
print psutil.__version__
for idx, pid in enumerate(psutil.process_iter()):
    print(
        pid.name, 
        pid.get_memory_info(), 
        pid.get_cpu_percent(),
        pid.cmdline,
        pid.path)
    if idx > 10:
        break

Here is the output:

sheats$ sudo python monitor.py 
0.2.0
('Python', meminfo(rss=15409152, vms=2521968640), 99.170133111480865, [], '')
('taskgated', meminfo(rss=1101824, vms=2503290880), 0.0, [], '')
('curl', meminfo(rss=1232896, vms=2494472192), 0.0, [], '')
('bash', meminfo(rss=815104, vms=2493915136), 0.0, [], '')
('launchd', meminfo(rss=692224, vms=2515070976), 0.0, [], '')
('sh', meminfo(rss=671744, vms=2493915136), 0.0, [], '')
('cron', meminfo(rss=253952, vms=2494431232), 0.0, [], '')
('ocspd', meminfo(rss=1290240, vms=2493534208), 0.0, [], '')
('mdworker', meminfo(rss=3661824, vms=2525724672), 0.0, [], '')
('mdworker', meminfo(rss=15003648, vms=2547027968), 0.0, [], '')
('HPScanner', meminfo(rss=8761344, vms=2816696320), 0.0, [], '')
('Pandora', meminfo(rss=142168064, vms=598204416), 0.0, [], '')

Any other ideas?

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on August 27, 2010 09:45:58

Make sure you're using the latest version from SVN, the code was 
changed recently as part of a related issue with cmdline/path. It 
could be you're running an older version than SVN that does not 
include those changes.

@giampaolo
Copy link
Owner Author

From she...@gmail.com on August 27, 2010 11:42:56

I'm using the latest, r633

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on August 27, 2010 23:03:57

Very odd, if I run your test code with r633 I get the below output 
(OS X 10.6.4, 32bit, default Python 2.6.1)

[jloden@macbook jloden]$ sudo python monitor.py 
0.2.0
('python', meminfo(rss=3624960, vms=81309696), 99.741251848201088, 
['python', 'monitor.py'], '')
('mdworker', meminfo(rss=2379776, vms=108736512), 0.0, 
['/System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker',
 'MDSImporterWorker', 'com.apple.Spotlight.ImporterWorker.89'], 
'/System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support')

('bash', meminfo(rss=1019904, vms=614748160), 0.0, ['/bin/bash', '--login'], '/bin')


What version of OS X are you on, and is this 64bit or 32bit OS? Are 
you using the version of python that comes installed with it or did 
you install another version? 

-Jay

Labels: OpSys-OSX

@giampaolo
Copy link
Owner Author

From she...@gmail.com on August 30, 2010 12:35:42

I'm using OS X 10.6.4, 64bit.  I'm using Python 2.6.4 from macports.

Let me know if I can help at all -- I'd be glad to debug some for you if you need me to.

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on August 30, 2010 12:59:31

It looks like you're running into a previously reported bug, Issue 
#83 : https://code.google.com/p/psutil/issues/detail?id=83 This 
appears to only affect 64bit systems, which I unfortunately don't 
have to test against. If you're familiar with C code you're more than 
welcome to try debugging it further (you can see how far we got in 
the comments/history from Issue #83 ). I suspect the structures for 
sysctl() are slightly different in 64bit versions of OS X but without 
having a system handy to compile against it's almost impossible to 
figure out the cause.

Since this is a dupe I'm going to merge the two bug #s but I'm more 
than happy to continue troubleshooting it with you if you don't mind 
assisting. I'd love to get this fixed for our next release. 

-Jay

Status: Duplicate
Mergedinto: 83

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:54:10

Updated csets after the SVN -> Mercurial migration: r264 == revision 
6fb382b64faf r633 == revision 258bf4fe8bb7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant