From 42af938b799ebaa1a7a1db4e2a4a905b1c3b5264 Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Thu, 27 Aug 2020 22:03:49 +0100 Subject: [PATCH] Rescue Errno::EPERM The api we call to get task info will raise this if you don't have permission (eg trying to get info about another user's processes when not root). By returning nil we'll fall back to the base case of shelling out to `ps` (which doesn't have this issue because `ps` is installed setuid & with the correct entitlements for this) --- lib/get_process_mem.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/get_process_mem.rb b/lib/get_process_mem.rb index 762fae0..67aaf25 100644 --- a/lib/get_process_mem.rb +++ b/lib/get_process_mem.rb @@ -120,5 +120,7 @@ def ps_memory def darwin_memory Darwin.resident_size(pid) + rescue Errno::EPERM + nil end end