Skip to content

Commit 65986a2

Browse files
committed
allow running as normal user when specifying pids
Fixes issue #28
1 parent 6a85491 commit 65986a2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ps_mem.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def open(self, *args):
121121
except (IOError, OSError):
122122
val = sys.exc_info()[1]
123123
if (val.errno == errno.ENOENT or # kernel thread or process gone
124-
val.errno == errno.EPERM):
124+
val.errno == errno.EPERM or
125+
val.errno == errno.EACCES):
125126
raise LookupError
126127
raise
127128

@@ -302,7 +303,8 @@ def getCmdName(pid, split_args, discriminate_by_pid):
302303
except OSError:
303304
val = sys.exc_info()[1]
304305
if (val.errno == errno.ENOENT or # either kernel thread or process gone
305-
val.errno == errno.EPERM):
306+
val.errno == errno.EPERM or
307+
val.errno == errno.EACCES):
306308
raise LookupError
307309
raise
308310

@@ -538,9 +540,9 @@ def print_memory_usage(sorted_cmds, shareds, count, total, swaps, total_swap,
538540
("-" * 33, " " * 24, human(total), "=" * 33))
539541

540542

541-
def verify_environment():
542-
if os.geteuid() != 0:
543-
sys.stderr.write("Sorry, root permission required.\n")
543+
def verify_environment(pids_to_show):
544+
if os.geteuid() != 0 and not pids_to_show:
545+
sys.stderr.write("Sorry, root permission required, or specify pids with -p\n")
544546
sys.stderr.close()
545547
sys.exit(1)
546548

@@ -560,7 +562,7 @@ def main():
560562
split_args, pids_to_show, watch, only_total, discriminate_by_pid, \
561563
show_swap = parse_options()
562564

563-
verify_environment()
565+
verify_environment(pids_to_show)
564566

565567
if not only_total:
566568
print_header(show_swap, discriminate_by_pid)

0 commit comments

Comments
 (0)