From 74048dee6c1c2edb4cef1d494ad36aa4018dbd5f Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 10 Sep 2019 08:09:48 -0700 Subject: [PATCH] Make a function actually work (not throw an exception) --- dool | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dool b/dool index ecfacfd..324eec3 100755 --- a/dool +++ b/dool @@ -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('-'): @@ -2363,6 +2367,7 @@ def getnamebypid(pid, name): if not ret: raise except: ret = basename(name) + return ret def getcpunr():