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

get/set process nice-ness #142

Closed
giampaolo opened this issue May 23, 2014 · 8 comments
Closed

get/set process nice-ness #142

giampaolo opened this issue May 23, 2014 · 8 comments

Comments

@giampaolo
Copy link
Owner

From g.rodola on December 25, 2010 18:45:49

= Proposal  
= 

Add the possibility to get/set the process niceness (priority) as when using 
"nice" and "renice" cmdline utilities.

= Implementation = 

Getting process niceness should be quite easy across all UNIX platforms.
For setting it we need to use setpriority(): 
http://linux.die.net/man/2/setpriority Being it a POSIX standard we can have a 
unique C implementation for Linux, OSX and FreeBSD we can add in a new 
psutil/_psutil_posix.c file.
This worries me a little since that would mean that we start to require 
*compiling* psutil on Linux, which is the only platform for which we used a 
100% pure python implementation. We can avoid that by using ctypes module: 
http://stackoverflow.com/questions/1920952/linux-group-scheduling-for-user-not-being-applied-to-setuid-ed-process
 ...but unfortunately ctypes is available only in Python 2.5 (and we support 2.4).
One solution could be to decide whether using ctypes or _psutil_posix.c at 
runtime in setup.py, depending on whether we manage to import ctypes.

= API =

My idea is to have a unique "nice" property which can be used for both getting 
and setting process niceness, as such:

>>> p = psutil.Process(3134)
>>> p.nice
0
>>> p.nice = 10
>>> p.nice
10

= Windows = 

I think there's something similar for windows as well, altough it goes under a 
different name. I haven't looked into it yet though.

Original issue: http://code.google.com/p/psutil/issues/detail?id=142

@giampaolo giampaolo self-assigned this May 23, 2014
@giampaolo
Copy link
Owner Author

From g.rodola on December 25, 2010 13:17:11

Implemented in r855 and r856 .
I added a new _psutil_posix.c module which is invoked also on Linux for now.
We'll see later whether using the ctypes variant.

Status: FixedInSVN

@giampaolo
Copy link
Owner Author

From g.rodola on December 25, 2010 13:46:06

On Windows this is possible by using GetPriorityClass and SetPriorityClass 
functions: http://msdn.microsoft.com/en-us/library/ms686219(v=vs.85).aspx 
http://msdn.microsoft.com/en-us/library/ms683211(v=vs.85).aspx We'll also have 
to expose all the *_PRIORITY_CLASS constants, presumably accessible as 
psutil.*_PRIORITY_CLASS.

Status: ReOpened

@giampaolo
Copy link
Owner Author

From g.rodola on December 25, 2010 13:46:18

Labels: Progress-3in4

@giampaolo
Copy link
Owner Author

From g.rodola on December 26, 2010 16:37:49

Implemented on Windows in r861 .
*_PRIORITY_CLASS constants are defined at psutil module level.

I wonder if it is a good idea to rename this as "priority" rather than "nice".
For Windows it would definitively make sense but on UNIX I'm not sure whether 
there's a difference between the two terms.

Maybe provide both names making Process.priority be an alias for Process.nice?

Status: FixedInSVN
Labels: -OpSys-UNIX OpSys-All

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on December 27, 2010 11:54:09

Python in other instances tends to side with the UNIX model and adapt Windows 
to it rather than the other way around. For example stat() in Python even 
though not all fields are available/relevant on Windows, or our use of kill() 
rather than TerminateProcess() etc. 

I suggest sticking with "nice" since it's the terminology for every other 
platform except windows and priority is the same concept anyway.

@giampaolo
Copy link
Owner Author

From g.rodola on March 20, 2011 14:55:37

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on June 09, 2011 15:33:51

Labels: -OpSys-All

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:57:36

Updated csets after the SVN -> Mercurial migration: r855 == revision 
d4a210bfdf95 r861 == revision f818d19e5160

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

1 participant