[Baypiggies] TypeError in os.path.realpath

Lincoln Peters anfrind at gmail.com
Wed May 30 21:05:50 CEST 2012


I mis-spoke in my original post.  I'm trying to read the symlink at
/proc/<PID>/exe, not the command-line arguments at /proc/<PID>/cmdline.

Sorry about that.
On May 30, 2012 11:05 AM, "Mitch Patenaude" <patenaude at gmail.com> wrote:

> I believe the problem is that /proc/<PID>/cmd has the whole command
> string, including arguments, separated by NULLs (\x00).  The commands
> without arguments just look like a null terminated string, but the ones
> with arguments have nulls interspersed in the middle of the string.  You
> probably want to split on \x00, and then take only the first element of the
> tuple.
>
>   --  Mitch
>
>
> On Wed, May 30, 2012 at 9:33 AM, Lincoln Peters <anfrind at gmail.com> wrote:
>
>> I'm developing a Python tool to monitor some of our Linux servers
>> (running RHEL 5.6 and Python 2.4).  In some cases, I need to track down the
>> executable file for a running process, which I should be able to by
>> resolving the symlink at /proc/<PID>/cmd.  When I use the "readlink"
>> command at the shell, it works correctly, but sometimes when I call
>> os.path.realpath with the exact same path, I get a TypeError the following
>> traceback (note: copied by hand since the servers have no Internet access):
>>
>> File "/usr/lib64/python2.4/posixpath.py", line 423, in realpath
>>   resolved = _resolve_link(component)
>> File "/usr/lib64/python2.4/posixpath.py", line 440, in _resolve_link
>>   while islink(path):
>> File "/usr/lib64/python2.4/posixpath.py", line 159, in islink
>>   st = os.lstat(path)
>> TypeError: lstat() argument 1 must be (encoded string without NULL
>> bytes), not str
>>
>> Strangely, this only happens with some processes and not others, and I
>> can't discern any pattern.  Any thoughts?
>>
>> Thanks in advance.
>>
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20120530/0c2d71ed/attachment.html>


More information about the Baypiggies mailing list