Skip to content

Commit

Permalink
Make a function actually work (not throw an exception)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottchiefbaker committed Sep 10, 2019
1 parent 64c2cc4 commit 74048de
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dool
Expand Up @@ -2350,11 +2350,15 @@ def basename(name):
def getnamebypid(pid, name):
"Return the name of a process by taking best guesses and exclusion"
ret = None

try:
#### man proc tells me there should be nulls in here, but sometimes it seems like spaces (esp google chrome)
# cmdline = open('/proc/%s/cmdline' % pid).read().split(('\0', ' '))
cmdline = linecache.getline('/proc/%s/cmdline' % pid, 1).split(('\0', ' '))
ret = basename(cmdline[0])
# cmdline = open('/proc/%s/cmdline' % pid).read().split(('\0', ' '))

cmdline = linecache.getline('/proc/%s/cmdline' % pid, 1).split('\0')
ret = basename(cmdline[0])

# Strip off any scripting language name
if ret in ('bash', 'csh', 'ksh', 'perl', 'python', 'ruby', 'sh'):
ret = basename(cmdline[1])
if ret.startswith('-'):
Expand All @@ -2363,6 +2367,7 @@ def getnamebypid(pid, name):
if not ret: raise
except:
ret = basename(name)

return ret

def getcpunr():
Expand Down

0 comments on commit 74048de

Please sign in to comment.