PFZheng / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

ionice - get/set process IO priority #147

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've just found this interesting article:
http://friedcpu.wordpress.com/2007/07/17/why-arent-you-using-ionice-yet/
...describing how, on Linux, the "renice" command can be used to change the IO 
priority of a process.
Proposal is to add this functionality in psutil by adding a new property to the 
Process class which permits to  get and set/change process IO priority.

= API = 

This should be the same we used for process niceness/priority (issue 142), 
consisting in a unique property for both getting and setting process IO 
priority.
IOPRIO_CLASS_RT, IOPRIO_CLASS_BE and IOPRIO_CLASS_IDLE constants should be 
exposed as well.
Example:

>>> psutil.Process(os.getpid())
>>> psutil.ionice
0
>>> psutil.ionice = psutil.IOPRIO_CLASS_RT
>>> psutil.ionice
2

= Linux implementation = 

renice source code: 
http://www.kernel.org/pub/linux/utils/util-linux-ng/v2.19/util-linux-2.19-rc1.ta
r.gz 

ioprio_get() and ioprio_set() system calls:
http://linux.die.net/man/2/ioprio_get
http://linux.die.net/man/2/ioprio_set

= Other platforms = 

FreeBSD (and probably OSX as well) seems not to have this functionnality yet 
although it might appear in the future:
http://old.nabble.com/ionice-in-FreeBSD--td27424108.html

On Windows this seems to be possible but only starting from Windows Vista:
http://forum.sysinternals.com/printer_friendly_posts.asp?TID=12767

As for now, my proposal is to provide this functionnality only on Linux.
On all other platforms Process.nice will just raise an AttributeError exception.

Original issue reported on code.google.com by g.rodola on 12 Jan 2011 at 1:11

GoogleCodeExporter commented 9 years ago

Original comment by g.rodola on 13 Jan 2011 at 10:45

GoogleCodeExporter commented 9 years ago
Implemented in r892.
I decided not to use a property but to split everything in two separate 
functions, get_ionice() and set_ionice(), because it must be possible to 
differentiate priority class and level (see ionice command).

Original comment by g.rodola on 13 Jan 2011 at 10:25

GoogleCodeExporter commented 9 years ago

Original comment by g.rodola on 20 Mar 2011 at 9:55

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Updated csets after the SVN -> Mercurial migration:
r892 == revision d17f087b01e3

Original comment by g.rodola on 2 Mar 2013 at 11:58