Skip to content

Instantly share code, notes, and snippets.

@antonym
Created February 14, 2017 20:41
Show Gist options
  • Save antonym/cbf705b928c290afd1798a10ed1f025f to your computer and use it in GitHub Desktop.
Save antonym/cbf705b928c290afd1798a10ed1f025f to your computer and use it in GitHub Desktop.
root@rpc-openstack:~# python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import psutil
>>> pid = 60712
>>> p = psutil.Process(pid)
>>> print p
psutil.Process(pid=60712, name='swift-proxy-ser')
>>> print p.cmdline
['/openstack/venvs/swift-r13.1.0rc1/bin/python', '/openstack/venvs/swift-r13.1.0rc1/bin/swift-proxy-server', '/etc/swift/proxy-server/proxy-server.conf']
>>> print p.cmdline[1].endswith
<built-in method endswith of str object at 0x7f1cdae1bc90>
>>> process_comm = p.cmdline[1]
>>> print process_comm
/openstack/venvs/swift-r13.1.0rc1/bin/swift-proxy-server
>>> head, tail = os.path.split(p.cmdline[1])
>>> print tail
swift-proxy-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment