diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-02-04 08:45:07 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-02-04 08:45:07 +0100 |
commit | fb675214541ce27939afd9866fc7b39489ccc422 (patch) | |
tree | 812753ec35ce7c5bfde4d8a22253dce57a210e9c | |
parent | 1ef408d2c3cf367f6f9d1dcd4752a99f46c11eb1 (diff) | |
download | psutil-fb675214541ce27939afd9866fc7b39489ccc422.tar.gz |
osx/linux ignore AccessDenied when retrieving pss/uss
-rw-r--r-- | psutil/_pslinux.py | 20 | ||||
-rw-r--r-- | psutil/_psosx.py | 7 |
2 files changed, 20 insertions, 7 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index bd6c3428..a5b79633 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -976,20 +976,28 @@ class Process(object): with open_binary("%s/%s/statm" % (self._procfs_path, self.pid)) as f: vms, rss, shared, text, lib, data, dirty = \ [int(x) * PAGESIZE for x in f.readline().split()[:7]] + + uss = pss = 0 if HAS_SMAPS: # Note: using two regexes is faster than reading the file # line by line. # XXX: on Python 3 the 2 regexes are 30% slower than on # Python 2 though. Figure out why. - with open_binary("%s/%s/smaps" % (self._procfs_path, self.pid), - buffering=BIGGER_FILE_BUFFERING) as f: - smaps_data = f.read() - uss = sum(map(int, _private_re.findall(smaps_data))) * 1024 - pss = sum(map(int, _shared_re.findall(smaps_data))) * 1024 + try: + with open_binary("%s/%s/smaps" % (self._procfs_path, self.pid), + buffering=BIGGER_FILE_BUFFERING) as f: + smaps_data = f.read() + except EnvironmentError as err: + if err.errno not in (errno.EPERM, errno.EACCES): + raise + else: + uss = sum(map(int, _private_re.findall(smaps_data))) * 1024 + pss = sum(map(int, _shared_re.findall(smaps_data))) * 1024 else: # usually means we're on kernel < 2.6.14 or CONFIG_MMU kernel # configuration option is not enabled. - uss = pss = 0 + pass + return pextmem(rss, vms, shared, text, lib, data, dirty, uss, pss) if HAS_SMAPS: diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 3c8abc60..420b5109 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -275,7 +275,12 @@ class Process(object): @wrap_exceptions def memory_info_ex(self): rss, vms, pfaults, pageins = cext.proc_memory_info(self.pid) - uss = cext.proc_memory_uss(self.pid) + uss = 0 + try: + uss = cext.proc_memory_uss(self.pid) + except OSError as err: + if err.errno not in (errno.EPERM, errno.EACCES): + raise return pextmem(rss, vms, pfaults * PAGESIZE, pageins * PAGESIZE, uss) @wrap_exceptions |