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

Fixing cmdline() parsing on linux #633

Closed
wants to merge 1 commit into from
Closed

Fixing cmdline() parsing on linux #633

wants to merge 1 commit into from

Conversation

arnimarj
Copy link
Contributor

I had problems getting the correct Process.cmdline() when some of the parameters were the empty string. E.g. when running this script:

import psutil, os, sys

pid = os.getpid()

for p in psutil.process_iter():
    if p.pid == os.getpid():
        break

    p = None

A = sys.argv[:]
B = p.cmdline()[1:]

print A
print B
print A == B```

A and B would not be the same when running ```python ../proc.py '' ''```

It seems that /proc/{pid}/cmdline contains strings separated by the zero byte, along with a final zero byte: http://linux.die.net/man/5/proc

This patch seems to fix the issue.

@arnimarj arnimarj closed this Jun 16, 2015
@giampaolo
Copy link
Owner

duplicate of #634

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

Successfully merging this pull request may close these issues.

None yet

2 participants