Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil fails to return the nice value for some processes on Solaris 10 #1194

Closed
gsauthof opened this issue Dec 13, 2017 · 1 comment
Closed

Comments

@gsauthof
Copy link
Contributor

How to reproduce - chose xntp on Solaris 10:

>>> p = psutil.Process(960)
>>> p.name()
'xntpd'
>>> p.nice()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/venv/lib/python3.5/site-packages/psutil/__init__.py", line 755, in nice
return self._proc.nice_get()
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 346, in wrapper
return fun(self, *args, **kwargs)
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 451, in nice_get
return cext_posix.getpriority(self.pid)
OSError: [Errno 22] Invalid argument

The system's ps is able to return the nice value:

$ ps -e -o pid,uid,gid,ruid,nice | grep 960
   960     0     0     0 RT

A simple C test program that just calls getpriority() on that PID also fails with EINVAL.

Perhaps getpriority() always fails for realtime processes, on Solaris 10. Is kind of plausible - since priorities doesn't really make sense for realtime. The man page doesn't include details on that topic, though.

This breaks psutil.process_iter() unless one uses a non-default attribute set that doesn't include 'nice'. Example how to make it fail with a minimal attribute set:

>>> for p in psutil.process_iter(): print(p.as_dict(attrs=['nice']))
{'nice': 0}
{'nice': -20}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/venv/lib/python3.5/site-packages/psutil/__init__.py", line 574, in as_dict
ret = meth()
  File "/path/to/venv/lib/python3.5/site-packages/psutil/__init__.py", line 755, in nice
return self._proc.nice_get()
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 346, in wrapper
return fun(self, *args, **kwargs)
  File "/path/to/venv/lib/python3.5/site-packages/psutil/_pssunos.py", line 451, in nice_get
return cext_posix.getpriority(self.pid)
OSError: [Errno 22] Invalid argument

The psutil Solaris-specific code contains a note regarding getpriority() vs. psinfo that mentions issue #1082.

There are several ways how to fix this:

  • call getpriority() first and fall back to psinfo
  • switch to psinfo as it's good enough for ps
  • default to 0 if getpriority() fails

See also:

@giampaolo
Copy link
Owner

I would say let's just get priority from psinfo then. The change is simple. In _pssunos.py:

    @wrap_exceptions
    def nice_get(self):
        return self._proc_basic_info()[proc_info_map['nice']]

Can you check if this fixes the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants