OLD | NEW |
| (Empty) |
1 | |
2 <!-- saved from url=(0066)http://code.google.com/p/psutil/wiki/DocumentationDev?
show=content --> | |
3 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
4 <title>DocumentationDev</title> | |
5 <script src="./documentation_files/googleapis.client__plusone.js"></script></he
ad> | |
6 <body> | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 <div> | |
13 <table> | |
14 <tbody><tr> | |
15 | |
16 | |
17 <td style="vertical-align:top; padding-left:5px"> | |
18 | |
19 <div id="wikicontent"> | |
20 <div class="vt" id="wikimaincol"> | |
21 <h1><a name="API_Reference"></a>API Reference<a href="http://code.google.com/p/
psutil/wiki/DocumentationDev?show=content#API_Reference" class="section_anchor">
</a></h1><h2><a name="Exceptions"></a>Exceptions<a href="http://code.google.com/
p/psutil/wiki/DocumentationDev?show=content#Exceptions" class="section_anchor"><
/a></h2><p>psutil.<strong>NoSuchProcess</strong><font size="3"><strong><tt>(</tt
></strong></font><i>pid, name=None, msg=None</i><font size="3"><strong><tt>)</tt
></strong></font> </p><blockquote>Raised when no process with the given PID is f
ound in the current process list or when a process no longer exists (zombie). | |
22 </blockquote><p></p><p>psutil.<strong>AccessDenied</strong><font size="3"><stron
g><tt>(</tt></strong></font><i>pid=None, name=None, msg=None</i><font size="3"><
strong><tt>)</tt></strong></font> </p><blockquote>Raised when permission to perf
orm an action is denied. | |
23 </blockquote><p></p><p>psutil.<strong>TimeoutExpired</strong><font size="3"><str
ong><tt>(</tt></strong></font><i>pid=None, name=None</i><font size="3"><strong><
tt>)</tt></strong></font> </p><blockquote>Raised on <tt>Process.wait(timeout)</t
t> if timeout expires and process is still alive. | |
24 </blockquote><p></p><blockquote><i><strong>New in 0.2.1</strong></i> | |
25 </blockquote><hr><h2><a name="Classes"></a>Classes<a href="http://code.google.co
m/p/psutil/wiki/DocumentationDev?show=content#Classes" class="section_anchor"></
a></h2><p>psutil.<strong>Process</strong><font size="3"><strong><tt>(</tt></stro
ng></font><i>pid</i><font size="3"><strong><tt>)</tt></strong></font> </p><block
quote>A class which represents an OS process. | |
26 </blockquote><ul><li><strong>pid</strong><br>The process pid. </li></ul><ul><li>
<strong>ppid</strong><br>The process parent pid. </li></ul><ul><li><strong>paren
t</strong><br>Return the parent process as a <tt>Process</tt> object. If no ppid
is known then return <tt>None</tt>. </li></ul><ul><li><strong>name</strong><br>
The process name. </li></ul><ul><li><strong>exe</strong><br>The process executab
le as an absolute path name. </li></ul><ul><li><strong>cmdline</strong><br>The c
ommand line process has been called with. </li></ul><ul><li><strong>create_time<
/strong><br> The process creation time as a floating point number expressed in s
econds since the epoch, in <a href="http://en.wikipedia.org/wiki/Coordinated_Uni
versal_Time" rel="nofollow">UTC</a>. </li><pre class="prettyprint">>>>
import os, psutil, datetime | |
27 >>> p = psutil.Process(os.getpid()) | |
28 >>> p.create_time | |
29 1307289803.47 | |
30 >>> datetime.datetime.fromtimestamp(p.create_time).strftime("%Y-%M-%d %
H:%M") | |
31 '2011-03-05 18:03'</pre></ul><ul><li><strong>uids</strong><br>The <i>real</i>, <
i>effective</i> and <i>saved</i> user ids of the current process as a nameduple.
This is the same as <a href="http://docs.python.org/library/os.html#os.getresui
d" rel="nofollow">os.getresuid()</a> but per-process. </li></ul><blockquote><i><
strong>New in 0.2.1</strong></i><br><strong><i>Availability:</i></strong><i> UNI
X</i> | |
32 </blockquote><ul><li><strong>gids</strong><br>The <i>real</i>, <i>effective</i>
and <i>saved</i> group ids of the current process as a nameduple. This is the sa
me as <a href="http://docs.python.org/library/os.html#os.getresgid" rel="nofollo
w">os.getresgid()</a> but per-process. </li></ul><blockquote><i><strong>New in 0
.2.1</strong></i><br><i><strong>Availability:</strong> UNIX</i> | |
33 </blockquote><ul><li><strong>username</strong><br>The name of the user that owns
the process. On UNIX this is calculated by using <i>real</i> process uid. </li>
</ul><blockquote><i><strong>Changed in 2.0:</strong> Windows implementation has
been rewritten in C for performace and <a href="http://sourceforge.net/projects/
pywin32/" rel="nofollow">pywin32</a> extension is no longer required.</i> | |
34 </blockquote><ul><li><strong>terminal</strong><br>The terminal associated with t
his process, if any, else None. This is similar to "tty" command but per-process
. </li></ul><blockquote><i><strong>New in 0.3.0</strong></i><br><i><strong>Avail
ability:</strong> UNIX</i> | |
35 </blockquote><ul><li><strong>status</strong><br>The current process status. The
return value is one of the <tt>STATUS_*</tt> constants, which is an integer that
can be used in conjunction with str() to obtain a human-readable form of the cu
rrent process status. Example: </li><pre class="prettyprint">>>> import
psutil, os | |
36 >>> p = psutil.Process(os.getpid()) | |
37 >>> p.status | |
38 0 | |
39 >>> p.status == psutil.STATUS_RUNNING | |
40 True | |
41 >>> str(p.status) | |
42 'running' | |
43 >>></pre></ul><blockquote><i><strong>New in 2.1</strong></i> | |
44 </blockquote><ul><li><strong>nice</strong><br>Get or set process <a href="http:/
/blogs.techrepublic.com.com/opensource/?p=140" rel="nofollow">niceness</a> (prio
rity). On UNIX this is a number which usually goes from -20 to 20. The higher th
e nice value, the lower the priority of the process. </li><pre class="prettyprin
t">>>> p = psutil.Process(os.getpid()) | |
45 >>> p.nice | |
46 0 | |
47 >>> p.nice = 10 # set/change process priority | |
48 >>> p.nice | |
49 10</pre></ul><blockquote>On Windows this is available as well by using <a href="
http://msdn.microsoft.com/en-us/library/ms683211(v=vs.85).aspx" rel="nofollow">G
etPriorityClass</a> and <a href="http://msdn.microsoft.com/en-us/library/ms68621
9(v=vs.85).aspx" rel="nofollow">SetPriorityClass</a>. <tt>psutil.*_PRIORITY_CLAS
S</tt> constants (explained <a href="http://msdn.microsoft.com/en-us/library/ms6
86219(v=vs.85).aspx" rel="nofollow">here</a>) can be used in conjunction. Exampl
e which increases process priority: | |
50 </blockquote><blockquote><pre class="prettyprint">>> p.nice = psutil.HIGH_
PRIORITY_CLASS</pre> | |
51 </blockquote><blockquote><i><strong>New in 2.1</strong></i> | |
52 </blockquote><ul><li><strong>getcwd</strong><font size="3"><strong><tt>()</tt></
strong></font><br>Return a string representing the process current working direc
tory. </li></ul><blockquote><i><strong>Availability:</strong> Windows, Linux</i>
| |
53 </blockquote><ul><li><strong>get_io_counters</strong><font size="3"><strong><tt>
()</tt></strong></font><br>Return process I/O statistics as a namedtuple includi
ng the number of read and write operations performed by the process and the amou
nt of bytes read and written. For linux refer to <a href="http://www.mjmwired.ne
t/kernel/Documentation/filesystems/proc.txt#1304" rel="nofollow">/proc filesysem
documentation</a>. On BSD there's apparently no way to retrieve bytes counters,
hence <tt>-1</tt> is returned for <tt>read_bytes</tt> and <tt>write_bytes</tt>
fields. OSX is not supported. </li><pre class="prettyprint">>>> p.get_i
o_counters() | |
54 io(read_count=454556, write_count=3456, read_bytes=110592, write_bytes=0)</pre><
/ul><blockquote><i><strong>New in 2.1</strong></i><br><i><strong>Availability:</
strong> Linux, Windows, FreeBSD</i> | |
55 </blockquote><ul><li><strong>get_ionice</strong><font size="3"><strong><tt>()</t
t></strong></font><br>Return <a href="http://friedcpu.wordpress.com/2007/07/17/w
hy-arent-you-using-ionice-yet/" rel="nofollow">process I/O niceness</a> (priorit
y) as a namedtuple including priority class and priority data. See <tt>set_ionic
e</tt> below for more information. </li></ul><blockquote><i><strong>New in 2.1</
strong></i><br><i><strong>Availability:</strong> Linux</i> | |
56 </blockquote><ul><li><strong>set_ionice</strong><font size="3"><strong><tt>(</tt
></strong></font><i>ioclass, value=None</i><font size="3"><strong><tt>)</tt></st
rong></font><br>Change <a href="http://friedcpu.wordpress.com/2007/07/17/why-are
nt-you-using-ionice-yet/" rel="nofollow">process I/O niceness</a> (priority). <i
>ioclass</i> is one of the <strong><tt>IOPRIO_CLASS_*</tt></strong> constants. <
i>value</i> is a number which goes from 0 to 7. The higher <i>value</i> value, t
he lower the I/O priority of the process. For further information refer to <a hr
ef="http://linux.die.net/man/1/ionice" rel="nofollow">ionice</a> command line ut
ility or <a href="http://linux.die.net/man/2/ioprio_set" rel="nofollow">ioprio_s
et</a> system call. The example below sets IDLE priority class for the current p
rocess, meaning it will only get I/O time when no other process needs the disk:
</li><pre class="prettyprint">>>> import psutil, os | |
57 >>> p = psutil.Process(os.getpid()) | |
58 >>> p.set_ionice(psutil.IOPRIO_CLASS_IDLE) | |
59 >>></pre></ul><blockquote><i><strong>New in 2.1</strong></i><br><i><str
ong>Availability:</strong> Linux</i> | |
60 </blockquote><ul><li><strong>get_num_threads</strong><font size="3"><strong><tt>
()</tt></strong></font><br>Return the number of threads used by this process. </
li></ul><ul><li><strong>get_threads</strong><font size="3"><strong><tt>()</tt></
strong></font><br>Return threads opened by process as a list of namedtuples incl
uding thread id and thread CPU times (user/system). </li></ul><blockquote><i><st
rong>New in 0.2.1</strong></i> | |
61 </blockquote><ul><li><strong>get_cpu_times</strong><font size="3"><strong><tt>()
</tt></strong></font><br>Return a tuple whose values are process CPU user and sy
stem times which means the amount of time expressed in seconds that a process ha
s spent in <a href="http://stackoverflow.com/questions/556405/what-do-real-user-
and-sys-mean-in-the-output-of-time1" rel="nofollow">user/system mode</a>. </li><
/ul><ul><li><strong>get_cpu_percent</strong><font size="3"><strong><tt>(</tt></s
trong></font><i>interval=0.1</i><font size="3"><strong><tt>)</tt></strong></font
><br>Return a float representing the process CPU utilization as a percentage. Wh
en interval is > 0.0 compares process times to system CPU times elapsed befor
e and after the interval (blocking). When interval is 0.0 or None compares proce
ss times to system CPU times elapsed since last call, returning immediately. In
this case is recommended for accuracy that this function be called with at least
0.1 seconds between calls. </li></ul><blockquote><i><strong>Changed in 0.2.0:</
strong> interval parameter was added</i> | |
62 </blockquote><ul><li><strong>get_memory_info</strong><font size="3"><strong><tt>
()</tt></strong></font><br>Return a tuple representing <a href="http://en.wikipe
dia.org/wiki/Resident_Set_Size" rel="nofollow">RSS</a> (Resident Set Size) and V
MS (Virtual Memory Size) in bytes.<br>On UNIX RSS and VMS are the same values sh
own by ps. On Windows RSS and VMS refer to "Mem Usage" and "VM Size" columns of
taskmgr.exe. </li></ul><ul><li><strong>get_memory_percent</strong><font size="3"
><strong><tt>()</tt></strong></font><br>Compare physical system memory to proces
s resident memory and calculate process memory utilization as a percentage. </li
></ul><ul><li><strong>get_children</strong><font size="3"><strong><tt>()</tt></s
trong></font><br>Return the children of this process as a list of <tt>Process</t
t> objects. </li></ul><ul><li><strong>get_open_files</strong><font size="3"><str
ong><tt>()</tt></strong></font><br>Return files opened by process as a list of <
a href="http://docs.python.org/library/collections.html?highlight=namedtuple#col
lections.namedtuple" rel="nofollow">namedtuples</a> including file absolute path
name and file descriptor. On <strong>FreeBSD</strong> this is done by parsing <
a href="http://en.wikipedia.org/wiki/Lsof" rel="nofollow">lsof</a> command outpu
t. If lsof is not installed on the system <a href="http://docs.python.org/librar
y/exceptions.html?highlight=notimplementederror#exceptions.NotImplementedError"
rel="nofollow">NotImplementedError</a> exception is raised. Example: </li><pre
class="prettyprint">>>> import psutil, os | |
63 >>> f = open('file.ext', 'w') | |
64 >>> p = psutil.Process(os.getpid()) | |
65 >>> p.get_open_files() | |
66 [openfile(path='/home/giampaolo/svn/psutil/file.ext', fd=3)]</pre></ul><blockquo
te><i><strong>Changed in 0.2.1:</strong> OSX implementation rewritten in C; no l
onger requiring lsof.</i> | |
67 </blockquote><ul><li><strong>get_connections</strong><font size="3"><strong><tt>
()</tt></strong></font><br>Return all TCP and UPD connections opened by process
as a list of <a href="http://docs.python.org/library/collections.html?highlight=
namedtuple#collections.namedtuple" rel="nofollow">namedtuples</a>. Every namedtu
ple provides 6 attributes:<br><br> </li><ul><li><strong>fd</strong>: the socket
file descriptor. This can be passed to <a href="http://docs.python.org/library/s
ocket.html#socket.fromfd" rel="nofollow">socket.fromfd</a> to obtain a usable so
cket object. This is only available on UNIX; on Windows <tt>-1</tt> is always re
turned.<br> </li><li><strong>family</strong>: the address family, either <a href
="http://docs.python.org/library/socket.html#socket.AF_INET" rel="nofollow">AF_I
NET</a> or <a href="http://docs.python.org/library/socket.html#socket.AF_INET6"
rel="nofollow">AF_INET6</a> <br> </li><li><strong>type</strong>: the address typ
e, either <a href="http://docs.python.org/library/socket.html#socket.SOCK_STREAM
" rel="nofollow">SOCK_STREAM</a> or <a href="http://docs.python.org/library/sock
et.html#socket.SOCK_DGRAM" rel="nofollow">SOCK_DGRAM</a> <br> </li><li><strong>l
ocal_address</strong>: the local address as a <tt>(ip, port)</tt> tuple. <br> </
li><li><strong>remote_address</strong>: the remote address as a <tt>(ip, port)</
tt> tuple. When the remote endpoint is not connected the tuple is empty. <br> </
li><li><strong>status</strong>: a string representing the TCP connections status
. String values are supposed to match Linux's <a href="http://students.mimuw.edu
.pl/lxr/source/include/net/tcp_states.h" rel="nofollow">tcp_states.h</a> header
file across all platforms. For UDP sockets this is always going to be an empty s
tring.<br> </li></ul></ul><blockquote>Example: | |
68 <pre class="prettyprint">>>> p = psutil.Process(1694) | |
69 >>> p.name | |
70 'firefox' | |
71 >>> p.get_connections() | |
72 [connection(fd=115, family=2, type=1, local_address=('10.0.0.1', 48776), remote_
address=('93.186.135.91', 80), status='ESTABLISHED'), | |
73 connection(fd=117, family=2, type=1, local_address=('10.0.0.1', 43761), remote_
address=('72.14.234.100', 80), status='CLOSING'), | |
74 connection(fd=119, family=2, type=1, local_address=('10.0.0.1', 60759), remote_
address=('72.14.234.104', 80), status='ESTABLISHED'), | |
75 connection(fd=123, family=2, type=1, local_address=('10.0.0.1', 51314), remote_
address=('72.14.234.83', 443), status='SYN_SENT')]</pre>On <strong>FreeBSD</stro
ng> this is implemented by parsing <a href="http://en.wikipedia.org/wiki/Lsof" r
el="nofollow">lsof</a> command output. If lsof is not installed on the system <a
href="http://docs.python.org/library/exceptions.html?highlight=notimplementeder
ror#exceptions.NotImplementedError" rel="nofollow">NotImplementedError</a> excep
tion is raised and for third party processes (different than <tt>os.getpid()</tt
>) results can differ depending on user privileges.<br> | |
76 </blockquote><blockquote><i><strong>Changed in 0.2.1:</strong> OSX implementatio
n rewritten in C; no longer requiring lsof.</i> | |
77 </blockquote><ul><li><strong>is_running</strong><font size="3"><strong><tt>()</t
t></strong></font><br>Return whether the current process is running in the curre
nt process list. </li></ul><ul><li><strong>send_signal</strong><font size="3"><s
trong><tt>(</tt></strong></font><i>signal</i><font size="3"><strong><tt>)</tt></
strong></font><br>Send a signal to process (see <a href="http://docs.python.org/
library/signal.html" rel="nofollow">signal module</a> constants). On Windows onl
y <tt>SIGTERM</tt> is valid and is treated as an alias for <tt>kill()</tt>. </li
></ul><ul><li><strong>suspend</strong><font size="3"><strong><tt>()</tt></strong
></font><br>Suspend process execution with <tt>SIGSTOP</tt> signal. On Windows t
his is done by suspending all process threads execution. </li></ul><ul><li><stro
ng>resume</strong><font size="3"><strong><tt>()</tt></strong></font><br>Resume p
rocess execution with <tt>SIGCONT</tt> signal. On Windows this is done by resumi
ng all process threads execution. </li></ul><ul><li><strong>terminate</strong><f
ont size="3"><strong><tt>()</tt></strong></font><br>Terminate the process with <
tt>SIGTERM</tt> signal. On Windows this is an alias for <tt>kill()</tt>. </li></
ul><ul><li><strong>kill</strong><font size="3"><strong><tt>()</tt></strong></fon
t><br>Kill the current process by using <tt>SIGKILL</tt> signal. </li></ul><bloc
kquote><i><strong>Changed in 0.2.0:</strong> no longer accepts <tt>sig</tt> keyw
ord argument - use <tt>send_signal()</tt> instead. </i> | |
78 </blockquote><ul><li><strong>wait</strong><font size="3"><strong><tt>(</tt></str
ong></font><i>timeout=None</i><font size="3"><strong><tt>)</tt></strong></font><
br>Wait for process termination and if the process is a children of the current
one also return the exit code, else <tt>None</tt>. On Windows there's no such li
mitation (exit code is always returned). If the process is already terminated do
es not raise <tt>NoSuchProcess</tt> exception but just return <tt>None</tt> imme
diately. If <i>timeout</i> is specified and process is still alive raises <tt>Ti
meoutExpired</tt> exception. </li></ul><blockquote><i><strong>New in 0.2.1</stro
ng></i> | |
79 </blockquote><p><br><br> psutil.<strong>Popen</strong><font size="3"><strong><tt
>(</tt></strong></font><tt>*args, **kwargs</tt><font size="3"><strong><tt>)</tt>
</strong></font> </p><blockquote>A more convenient interface to stdlib <a href="
http://docs.python.org/library/subprocess.html#subprocess.Popen" rel="nofollow">
subprocess.Popen</a>. It starts a sub process and deals with it exactly as when
using subprocess.Popen class but in addition also provides all the properties an
d methods of psutil.Process class in a unique interface. For method names common
to both classes such as <i>kill()</i> and <i>terminate()</i>, psutil.Process im
plementation takes precedence. For a complete documentation refers to <a href="h
ttp://docs.python.org/library/subprocess.html" rel="nofollow">subprocess module
documentation</a>. | |
80 <pre class="prettyprint">>>> import psutil | |
81 >>> from subprocess import PIPE | |
82 >>> p = psutil.Popen(["/usr/bin/python", "-c", "print 'hi'"], stdout=PI
PE) | |
83 >>> p.name | |
84 'python' | |
85 >>> p.uids | |
86 user(real=1000, effective=1000, saved=1000) | |
87 >>> p.username | |
88 'giampaolo' | |
89 >>> p.communicate() | |
90 ('hi\n', None) | |
91 >>> p.wait(timeout=2) | |
92 0 | |
93 >>></pre></blockquote><blockquote><i><strong>New in 0.2.1</strong></i> | |
94 </blockquote><hr><h2><a name="Functions"></a>Functions<a href="http://code.googl
e.com/p/psutil/wiki/DocumentationDev?show=content#Functions" class="section_anch
or"></a></h2><p>psutil.<strong>get_pid_list</strong><font size="3"><strong><tt>(
)</tt></strong></font><br> </p><blockquote>Return a list of current running PIDs
. | |
95 </blockquote><p></p><p>psutil.<strong>pid_exists</strong><font size="3"><strong>
<tt>(</tt></strong></font><i>pid</i><font size="3"><strong><tt>)</tt></strong></
font><br> </p><blockquote>Check whether the given PID exists in the current proc
ess list. This is faster than doing <tt>pid in psutil.get_pid_list()</tt> and sh
ould be preferred. | |
96 </blockquote><p></p><p>psutil.<strong>process_iter</strong><font size="3"><stron
g><tt>()</tt></strong></font><br> </p><blockquote>Return an iterator yielding a
Process class instances for all running processes on the local machine. This sho
uld be preferred over doing <tt>for pid in psutil.get_pid_list(): psutil.Process
(pid)</tt> as it safe from race conditions. | |
97 </blockquote><p></p><hr><h2><a name="System_related_functions"></a>System relate
d functions<a href="http://code.google.com/p/psutil/wiki/DocumentationDev?show=c
ontent#System_related_functions" class="section_anchor"></a></h2><h3><a name="CP
U"></a>CPU<a href="http://code.google.com/p/psutil/wiki/DocumentationDev?show=co
ntent#CPU" class="section_anchor"></a></h3><p>psutil.<strong>cpu_percent</strong
><font size="3"><strong><tt>(</tt></strong></font><i>interval=0.1, percpu=False<
/i><font size="3"><strong><tt>)</tt></strong></font><br> </p><blockquote>Return
a float representing the current system-wide CPU utilization as a percentage. Wh
en interval is > 0.0 compares system CPU times elapsed before and after the i
nterval (blocking). When interval is 0.0 or None compares system CPU times elaps
ed since last call or module import, returning immediately. In this case is reco
mmended for accuracy that this function be called with at least 0.1 seconds betw
een calls.<br>When <i>percpu</i> is True returns a list of floats representing t
he utilization as a percentage for each CPU. First element of the list refers t
o first CPU, second element to second CPU and so on. The order of the list is co
nsistent across calls. | |
98 </blockquote><p></p><pre class="prettyprint">>>> # blocking, system-wid
e | |
99 >>> psutil.cpu_percent(interval=1) | |
100 2.0 | |
101 >>> | |
102 >>> # blocking, per-cpu | |
103 >>> psutil.cpu_percent(interval=1, percpu=True) | |
104 [2.0, 1.0] | |
105 >>> | |
106 >>> # non-blocking (percentage since last call) | |
107 >>> psutil.cpu_percent(interval=0) | |
108 2.9 | |
109 >>></pre><blockquote><i><strong>Changed in 0.2.0:</strong> interval par
ameter was added</i><br><i><strong>Changed in 0.3.0:</strong> percpu parameter w
as added</i> | |
110 </blockquote><p>psutil.<strong>cpu_times</strong><font size="3"><strong><tt>(</t
t></strong></font><i>percpu=False</i><font size="3"><strong><tt>)</tt></strong><
/font><br> </p><blockquote>Return system CPU times as a namedtuple. Every attrib
ute represents the time CPU has spent in the given mode.<br>The attributes avail
ability varies depending on the platform. Here follows a list of all available
attributes: | |
111 </blockquote><blockquote>- user<br> | |
112 - system<br> | |
113 - idle<br> | |
114 - nice <i>(UNIX)</i><br> | |
115 - iowait <i>(Linux)</i><br> | |
116 - irq <i>(Linux, FreeBSD)</i><br> | |
117 - softirq <i>(Linux)</i> | |
118 </blockquote><p></p><blockquote>When <i>percpu</i> is True return a list of name
duples for each CPU. First element of the list refers to first CPU, second eleme
nt to second CPU and so on. The order of the list is consistent across calls. | |
119 </blockquote><blockquote><i><strong>Changed in 0.3.0:</strong> percpu parameter
was added</i> | |
120 </blockquote><hr><h3><a name="Memory"></a>Memory<a href="http://code.google.com/
p/psutil/wiki/DocumentationDev?show=content#Memory" class="section_anchor"></a><
/h3><p>psutil.<strong>phymem_usage</strong><font size="3"><strong><tt>()</tt></s
trong></font><br> </p><blockquote>Return the amount of total, used and free phys
ical memory on the system in bytes plus the percentage usage. | |
121 <p></p><pre class="prettyprint">>>> psutil.phymem_usage() | |
122 usage(total=4153868288, used=2854199296, free=1299668992, percent=34.6)</pre><i>
<strong>New in 0.3.0</strong></i> | |
123 </blockquote><p>psutil.<strong>virtmem_usage</strong><font size="3"><strong><tt>
()</tt></strong></font><br> </p><blockquote>Return the amount of total, used and
free virtual memory on the system in bytes plus the percentage usage.<br>On Lin
ux they match the values returned by <tt>free</tt> command line utility. On OS X
and FreeBSD they represent the same values as returned by <tt>sysctl vm.vmtotal
</tt>. On Windows they are determined by reading the <tt>*PageFile</tt> values o
f <a href="http://msdn.microsoft.com/en-us/library/aa366770(VS.85).aspx" rel="no
follow">MEMORYSTATUSEX</a> structure. | |
124 <p></p><pre class="prettyprint">>>> psutil.virtmem_usage() | |
125 usage(total=2097147904, used=4096, free=2097143808, percent=0.0)</pre><i><strong
>New in 0.3.0</strong></i> | |
126 </blockquote><p>psutil.<strong>cached_phymem</strong><font size="3"><strong><tt>
()</tt></strong></font><br> psutil.<strong>phymem_buffers</strong><font size="3"
><strong><tt>()</tt></strong></font><br> </p><blockquote>Return the amount of ca
ched memory and physical memory buffers on the system, in bytes. Thet reflects t
he "cached" and "buffers" columns of free command line utility on Linux. | |
127 </blockquote><p></p><blockquote><i><strong>Availability:</strong> Linux</i> | |
128 </blockquote><p>psutil.<strong>avail_phymem</strong><font size="3"><strong><tt>(
)</tt></strong></font><br> psutil.<strong>used_phymem</strong><font size="3"><st
rong><tt>()</tt></strong></font><br> psutil.<strong>total_virtmem</strong><font
size="3"><strong><tt>()</tt></strong></font><br> psutil.<strong>avail_virtmem</s
trong><font size="3"><strong><tt>()</tt></strong></font><br> psutil.<strong>used
_virtmem</strong><font size="3"><strong><tt>()</tt></strong></font><br> </p><blo
ckquote>These functions are deprecated by <i>psutil.phymem_usage()</i> and <i>ps
util.virtmem_usage()</i>. Use them instead. | |
129 </blockquote><p></p><blockquote><i><strong>Deprecated in 0.3.0</strong></i> | |
130 </blockquote><hr><h3><a name="Disk"></a>Disk<a href="http://code.google.com/p/ps
util/wiki/DocumentationDev?show=content#Disk" class="section_anchor"></a></h3><p
>psutil.<strong>disk_partitions</strong><font size="3"><strong><tt>(</tt></stron
g></font><i>all=False</i><font size="3"><strong><tt>)</tt></strong></font><br> <
/p><blockquote>Return all mounted disk partitions as a list of namedtuples inclu
ding device, mount point and filesystem type, similarly to "df" command on posix
. <br>If <i>all</i> parameter is False return physical devices only (e.g. hard d
isks, cd-rom drives, USB keys) and ignore all others (e.g. memory partitions suc
h as <a href="http://www.cyberciti.biz/tips/what-is-devshm-and-its-practical-usa
ge.html" rel="nofollow">/dev/shm</a>).<br> Namedtuple's 'fstype' field is a stri
ng which varies depending on the platform. <br>On Linux it can be one of the val
ues found in /proc/filesystems (e.g. 'ext3' for an ext3 hard drive o 'iso9660' f
or the CD-ROM drive). <br>On Windows it is determined via <a href="http://msdn.m
icrosoft.com/en-us/library/aa364939(v=vs.85).aspx" rel="nofollow">GetDriveType</
a> and can be either "removable", "fixed", "remote", "cdrom", "unmounted" or "ra
mdisk". <br>On OSX and FreeBSD it is retrieved via <a href="http://www.manpagez.
com/man/2/getfsstat/" rel="nofollow">getfsstat(2)</a>. <br>See <a href="http://p
sutil.googlecode.com/svn/trunk/examples/disk_usage.py" rel="nofollow">examples/d
isk_usage.py</a> script providing an example usage. | |
131 <p></p><pre class="prettyprint">>>> psutil.get_partitions() | |
132 [partition(device='/dev/sda3', mountpoint='/', fstype='ext4'), | |
133 partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')] | |
134 >>></pre></blockquote><blockquote><i><strong>New in 0.3.0</strong></i> | |
135 </blockquote><p>psutil.<strong>disk_usage</strong><font size="3"><strong><tt>(</
tt></strong></font><i>path</i><font size="3"><strong><tt>)</tt></strong></font><
br> </p><blockquote>Return disk usage statistics about the given <i>path</i> as
a namedtuple including total, used and free space expressed in bytes plus the pe
rcentage usage. OSError is raised if path does not exist. See <a href="http://ps
util.googlecode.com/svn/trunk/examples/disk_usage.py" rel="nofollow">examples/di
sk_usage.py</a> script providing an example usage. | |
136 <p></p><pre class="prettyprint">>>> psutil.disk_usage('/') | |
137 usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)</pre><
/blockquote><blockquote><i><strong>New in 0.3.0</strong></i> | |
138 </blockquote><hr><h2><a name="Constants"></a>Constants<a href="http://code.googl
e.com/p/psutil/wiki/DocumentationDev?show=content#Constants" class="section_anch
or"></a></h2><p>psutil.<strong>TOTAL_PHYMEM</strong><br> </p><blockquote>The amo
unt of total physical memory on the system, in bytes. | |
139 </blockquote><p></p><p>psutil.<strong>NUM_CPUS</strong><br> </p><blockquote>The
number of CPUs on the system. This is preferable than using <tt>os.environ['NUMB
ER_OF_PROCESSORS']</tt> as it is more accurate and always available. | |
140 </blockquote><p></p><p>psutil.<strong>BOOT_TIME</strong><br> </p><blockquote>A n
umber indicating the system boot time expressed in seconds since the epoch. | |
141 </blockquote><p></p><blockquote><i><strong>New in 0.2.1</strong></i> | |
142 </blockquote><p>psutil.<strong>ABOVE_NORMAL_PRIORITY_CLASS</strong><br> psutil.<
strong>BELOW_NORMAL_PRIORITY_CLASS</strong><br> psutil.<strong>HIGH_PRIORITY_CLA
SS</strong><br> psutil.<strong>IDLE_PRIORITY_CLASS</strong><br> psutil.<strong>N
ORMAL_PRIORITY_CLASS</strong><br> psutil.<strong>REALTIME_PRIORITY_CLASS</strong
><br> </p><blockquote>A set of integers representing the priority of a process o
n Windows (see <a href="http://msdn.microsoft.com/en-us/library/ms686219(v=vs.85
).aspx" rel="nofollow">MSDN documentation</a>). They can be used in conjunction
with <tt>psutil.Process.nice</tt> to get or set process priority. | |
143 </blockquote><p></p><blockquote><i><strong>New in 0.2.1</strong></i><br><i><stro
ng>Availability:</strong> Windows</i> | |
144 </blockquote><p>psutil.<strong>IOPRIO_CLASS_NONE</strong><br> psutil.<strong>IOP
RIO_CLASS_RT</strong><br> psutil.<strong>IOPRIO_CLASS_BE</strong><br> psutil.<st
rong>IOPRIO_CLASS_IDLE</strong><br> </p><blockquote>A set of integers representi
ng the I/O priority of a process on Linux. They can be used in conjunction with
<tt>psutil.Process.get_ionice()</tt> and <tt>psutil.Process.set_ionice()</tt> to
get or set process I/O priority. For further information refer to <a href="http
://linux.die.net/man/1/ionice" rel="nofollow">ionice</a> command line utility or
<a href="http://linux.die.net/man/2/ioprio_get" rel="nofollow">ioprio_get</a> s
ystem call. | |
145 </blockquote><p></p><blockquote><i><strong>New in 0.2.1</strong></i><br><i><stro
ng>Availability:</strong> Linux</i> | |
146 </blockquote><p>psutil.<strong>STATUS_RUNNING</strong><br> psutil.<strong>STATUS
_SLEEPING</strong><br> psutil.<strong>STATUS_DISK_SLEEP</strong><br> psutil.<str
ong>STATUS_STOPPED</strong><br> psutil.<strong>STATUS_TRACING_STOP</strong><br>
psutil.<strong>STATUS_ZOMBIE</strong><br> psutil.<strong>STATUS_DEAD</strong><br
> psutil.<strong>STATUS_WAKE_KILL</strong><br> psutil.<strong>STATUS_WAKING</str
ong><br> psutil.<strong>STATUS_IDLE</strong><br> psutil.<strong>STATUS_LOCKED</s
trong><br> psutil.<strong>STATUS_WAITING</strong><br> </p><blockquote>A set of i
ntegers representing the status of a process. To be used in conjunction with <tt
>psutil.Process.status</tt> property. If used with str() return a human-readable
status string. | |
147 </blockquote><p></p><blockquote><i><strong>New in 0.2.1</strong></i><br><i><stro
ng> | |
148 </strong></i></blockquote> | |
149 </div> | |
150 </div> | |
151 </td></tr><tr> | |
152 </tr></tbody></table> | |
153 </div> | |
154 | |
155 | |
156 | |
157 | |
158 <script type="text/javascript" src="./documentation_files/dit_scripts.js"></scri
pt> | |
159 | |
160 | |
161 <script type="text/javascript" src="./documentation_files/plusone.js"> | |
162 </script> | |
163 | |
164 | |
165 | |
166 | |
167 </body></html> | |
OLD | NEW |