Skip to content

OSX - AccessDenied for memory_info() / proc_pidinfo() #883

Closed
@ckaran

Description

@ckaran

I'm attempting to use psutil to determine when it's reasonable to spawn extra simulators for my work (too many simulations at once == using swap which slows things down). However, I'm getting a permissions error on the child process.

uname -a = Darwin XXX.local 13.4.0 Darwin Kernel Version 13.4.0: Mon Jan 11 18:17:34 PST 2016; root:xnu-2422.115.15~1/RELEASE_X86_64 x86_64

OS X 10.9.5

Python 3.4.5 (default, Jun 27 2016, 12:04:15) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information

psutil.__version__ == 4.3.1

Here are the steps to reproduce:

  • Copy the code below to a file named sleeper.c
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
    sleep(1000);
    return EXIT_SUCCESS;
}
  • Compile it using clang -Wall -Wextra -pedantic -std=c11 sleeper.c, and let the output file be named a.out.
  • Copy the code below to a file named ps_test.py in the same directory as sleeper.c.
import os
import os.path
import psutil

path = os.path.realpath(os.path.join(os.path.curdir, 'a.out'))
child = os.spawnl(os.P_NOWAIT, path)
process = psutil.Process(pid=child)
print(process.memory_info())
  • Run the python script as python ps_test.py.

Doing the above will result in the following:

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psutil/_psosx.py", line 244, in wrapper
    return fun(self, *args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psutil/_psosx.py", line 317, in memory_info
    rss, vms, pfaults, pageins = cext.proc_memory_info(self.pid)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ps_test.py", line 8, in <module>
    print(process.memory_info())
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psutil/__init__.py", line 998, in memory_info
    return self._proc.memory_info()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psutil/_psosx.py", line 252, in wrapper
    raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=94444)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions