OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <title>Documentation</title> |
| 4 </head> |
| 5 <body> |
| 6 |
| 7 <style> |
| 8 . |
| 9 </style> |
| 10 |
| 11 |
| 12 <div id="wikicontent"> |
| 13 <table width="100%" border="0" cellspacing="0" cellpadding="0"> |
| 14 <tr> |
| 15 |
| 16 <td class="vt" id="wikimaincol" width="100%"> |
| 17 |
| 18 <div id="wikiheader" style="margin-bottom:1em"> |
| 19 |
| 20 </div> |
| 21 <h1><a name="API_Reference"></a>API Reference<a href="#API_Reference" class="se
ction_anchor"></a></h1><h2><a name="Exceptions"></a>Exceptions<a href="#Exceptio
ns" class="section_anchor"></a></h2><p>psutil.<strong>NoSuchProcess</strong><fon
t size="3"><strong><tt>(</tt></strong></font><i>pid, name=None, msg=None</i><fon
t size="3"><strong><tt>)</tt></strong></font> <blockquote>Raised when no process
with the given PID was found in the current process list or when a process no l
onger exists (zombie). |
| 22 </blockquote></p><blockquote><i>Changed in 0.2.0: <tt>pid</tt>, <tt>name</tt> an
d <tt>msg</tt> arguments were added </i> |
| 23 </blockquote><p>psutil.<strong>AccessDenied</a></strong><font size="3"><strong><
tt>(</tt></strong></font><i>pid=None, name=None, msg=None</i><font size="3"><str
ong><tt>)</tt></strong></font> <blockquote>Raised when permission to perform an
action is denied. |
| 24 </blockquote></p><blockquote><i>Changed in 0.2.0: <tt>pid</tt>, <tt>name</tt> an
d <tt>msg</tt> arguments were added </i> |
| 25 </blockquote><hr/><h2><a name="Classes"></a>Classes<a href="#Classes" class="sec
tion_anchor"></a></h2><p>psutil.<strong>Process</strong><font size="3"><strong><
tt>(</tt></strong></font><i>pid</i><font size="3"><strong><tt>)</tt></strong></f
ont> </p><blockquote>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><blockquote><i>New in 0.2.0</i> |
| 27 </blockquote><ul><li><strong>cmdline</strong><br>The command line process has be
en called with. </li></ul><ul><li><strong>path</strong><br>The process path. </
li></ul><blockquote><i>Deprecated in 0.2.0</i> |
| 28 </blockquote><ul><li><strong>create_time</strong><br> The process creation time
as a floating point number expressed in seconds since the epoch, in <a href="htt
p://en.wikipedia.org/wiki/Coordinated_Universal_Time" rel="nofollow">UTC</a>. </
li></ul><ul><li><strong>uid</strong><br>The real user id of the current process.
Where uid doesn't make sense (<i>Windows</i>) always return <tt>-1</tt>.
</li></ul><ul><li><strong>gid</strong><br>The real group id of the current proce
ss. Where gid doesn't make sense (<i>Windows</i>) always return <tt>-1</tt
>. </li></ul><ul><li><strong>username</strong><br>The name of the user that owns
the process. </li></ul><blockquote><i>Changed in 2.0: Windows implementation ha
s been rewritten in C for performace and <a href="http://sourceforge.net/project
s/pywin32/" rel="nofollow">pywin32</a> extension is no longer required.</i> |
| 29 </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><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><blockquote><i>New in 0.2.0</i> |
| 30 </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>cpu_percent</strong><font size="3"><strong><tt>(</tt></stron
g></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. When i
nterval is > 0.0 compares process times to system CPU times elapsed before an
d after the interval (blocking). When interval is 0.0 or None compares process t
imes 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>Changed in 0.2.0: interval para
meter was added</i> |
| 31 </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 Si
ze" columns of taskmgr.exe. </li></ul><ul><li><strong>get_memory_percent</s
trong><font size="3"><strong><tt>()</tt></strong></font><br>Compare physical sys
tem memory to process resident memory and calculate process memory utilization a
s a percentage. </li></ul><ul><li><strong>get_children</strong><font size="3"><s
trong><tt>()</tt></strong></font><br>Return the children of this process as a li
st of <tt>Process</tt> objects. </li></ul><blockquote><i>New in 0.2.0</i> |
| 32 </blockquote><ul><li><strong>get_open_files</strong><font size="3"><strong><tt>(
)</tt></strong></font><br>Return files opened by process as a list of <a href="h
ttp://docs.python.org/library/collections.html?highlight=namedtuple#collections.
namedtuple" rel="nofollow">namedtuples</a> including file absolute path name and
file descriptor. On <strong>OSX</strong> and <strong>FreeBSD</strong> this is d
one by parsing <a href="http://en.wikipedia.org/wiki/Lsof" rel="nofollow">lsof</
a> command output. If lsof is not installed on the system <a href="http://docs.p
ython.org/library/exceptions.html?highlight=notimplementederror#exceptions.NotIm
plementedError" rel="nofollow">NotImplementedError</a> exception is raised. Exa
mple: </li><pre class="prettyprint">>>> import psutil, os |
| 33 >>> f = open('file.ext', 'w') |
| 34 >>> psutil.Process(os.getpid()).get_open_files() |
| 35 [openfile(path='/home/giampaolo/svn/psutil/file.ext', fd=3)]</pre></ul
><blockquote><i>New in 0.2.0</i> |
| 36 </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/
socket.html#socket.fromfd" rel="nofollow">socket.fromfd</a> to obtain a usable s
ocket object. This is only available on UNIX; on Windows <tt>-1</tt> is always r
eturned.<br> </li><li><strong>family</strong>: the address family, either <a hre
f="http://docs.python.org/library/socket.html#socket.AF_INET" rel="nofollow">AF_
INET</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 ty
pe, either <a href="http://docs.python.org/library/socket.html#socket.SOCK_STREA
M" rel="nofollow">SOCK_STREAM</a> or <a href="http://docs.python.org/library/soc
ket.html#socket.SOCK_DGRAM" rel="nofollow">SOCK_DGRAM</a> <br> </li><li><strong>
local_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 statu
s. String values are supposed to match Linux's <a href="http://students.mim
uw.edu.pl/lxr/source/include/net/tcp_states.h" rel="nofollow">tcp_states.h</a> h
eader file across all platforms. For UDP sockets this is always going to be an e
mpty string.<br> </li></ul></ul><blockquote>Example: |
| 37 <pre class="prettyprint">>>> p = psutil.Process(1694) |
| 38 >>> p.name |
| 39 'firefox' |
| 40 >>> p.get_connections() |
| 41 [connection(fd=115, family=2, type=1, local_address=('10.0.0.1', 48776
), remote_address=('93.186.135.91', 80), status='ESTABLISHED'
;), |
| 42 connection(fd=117, family=2, type=1, local_address=('10.0.0.1', 43761
), remote_address=('72.14.234.100', 80), status='CLOSING'), |
| 43 connection(fd=119, family=2, type=1, local_address=('10.0.0.1', 60759
), remote_address=('72.14.234.104', 80), status='ESTABLISHED'
;), |
| 44 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>OSX</strong> and <strong>FreeBSD</strong> this is implemented b
y parsing <a href="http://en.wikipedia.org/wiki/Lsof" rel="nofollow">lsof</a> co
mmand output. If lsof is not installed on the system <a href="http://docs.python
.org/library/exceptions.html?highlight=notimplementederror#exceptions.NotImpleme
ntedError" rel="nofollow">NotImplementedError</a> exception is raised. For third
party processes (different than <tt>os.getpid()</tt>) results can differ depend
ing on user privileges.<br> |
| 45 </blockquote><blockquote><i>New in 0.2.0</i> |
| 46 </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>suspend</strong><font size="3"><stron
g><tt>()</tt></strong></font><br>Suspend process execution. </li></ul><ul><li><s
trong>resume</strong><font size="3"><strong><tt>()</tt></strong></font><br>Resum
e process execution. </li></ul><ul><li><strong>terminate</strong><font size="3">
<strong><tt>()</tt></strong></font><br>Terminate the process with <tt>SIGTERM</t
t> signal. On Windows this is an alias for <tt>kill()</tt>. </li></ul><blockquot
e><i>New in 0.2.0</i> |
| 47 </blockquote><ul><li><strong>send_signal</strong><font size="3"><strong><tt>(</t
t></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 only <tt>SIGTERM<
/tt> is valid and is treated as an alias for <tt>kill()</tt>. </li></ul><blockqu
ote><i>New in 0.2.0</i> |
| 48 </blockquote><ul><li><strong>kill</strong><font size="3"><strong><tt>()</tt></st
rong></font><br>Kill the current process by using <tt>SIGKILL</tt> signal. </li>
</ul><blockquote><i>Changed in 0.2.0: no longer accepts <tt>sig</tt> keyword arg
ument - use <tt>send_signal()</tt> instead. </i> |
| 49 </blockquote><hr/><h2><a name="Functions"></a>Functions<a href="#Functions" clas
s="section_anchor"></a></h2><p>psutil.<strong>get_pid_list</strong><font size="3
"><strong><tt>()</tt></strong></font><br> <blockquote>Return a list of current r
unning PIDs. |
| 50 </blockquote></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></fon
t><br> <blockquote>Check whether the given PID exists in the current process lis
t. |
| 51 </blockquote></p><p>psutil.<strong>process_iter</strong><font size="3"><strong><
tt>()</tt></strong></font><br> <blockquote>Return an iterator yielding a Process
class instances for all running processes on the local machine. |
| 52 </blockquote></p><hr/><h2><a name="System_related_objects"></a>System related ob
jects<a href="#System_related_objects" class="section_anchor"></a></h2><p>psutil
.<strong>cpu_percent</strong><font size="3"><strong><tt>(</tt></strong></font><i
>interval=0.1</i><font size="3"><strong><tt>)</tt></strong></font><br> <blockquo
te>Return a float representing the current system-wide CPU utilization as a perc
entage. When interval is > 0.0 compares system CPU times elapsed before and a
fter the interval (blocking). When interval is 0.0 or None compares system CPU t
imes elapsed since last call or module import, returning immediately. In this ca
se is recommended for accuracy that this function be called with at least 0.1 se
conds between calls. |
| 53 </blockquote></p><blockquote><i>Changed in 0.2.0: interval parameter was added</
i> |
| 54 </blockquote><p>psutil.<strong>cpu_times</strong><font size="3"><strong><tt>()</
tt></strong></font><br> <blockquote>Return system CPU times as a <tt>CPUTimes</t
t> class object. Every CPU time is accessible in form of a <tt>CPUTimes</tt> att
ribute and represents the time CPU has spent in the given mode.<br>The attribute
s availability varies depending on the platform. Here follows a list of all ava
ilable attributes: |
| 55 </blockquote></p><blockquote>- <strong>user</strong><br> |
| 56 - <strong>system</strong><br> |
| 57 - <strong>idle</strong><br> |
| 58 - <strong>nice</strong> <i>(UNIX)</i><br> |
| 59 - <strong>iowait</strong> <i>(Linux)</i><br> |
| 60 - <strong>irq</strong> <i>(Linux, FreeBSD)</i><br> |
| 61 - <strong>softirq</strong> <i>(Linux)</i><br> |
| 62 </blockquote><p>psutil.<strong>TOTAL_PHYMEM</strong><br> psutil.<strong>avail_ph
ymem</strong><font size="3"><strong><tt>()</tt></strong></font><br> psutil.<stro
ng>used_phymem</strong><font size="3"><strong><tt>()</tt></strong></font><br> <b
lockquote>Return the amount of total, available and used physical memory on the
system, in bytes. |
| 63 </blockquote></p><p>psutil.<strong>cached_phymem</strong><font size="3"><strong>
<tt>()</tt></strong></font><br> <blockquote>Return the amount of cached memory o
n the system, in bytes. This reflects the "cached" column of free comm
and line utility on Linux. |
| 64 </blockquote></p><blockquote><i>New in 0.2.0</i><br><i>Availability: <strong>Lin
ux</strong></i> |
| 65 </blockquote><p>psutil.<strong>phymem_buffers</strong><font size="3"><strong><tt
>()</tt></strong></font><br> <blockquote>Return the amount of physical memory bu
ffers used by the kernel in bytes. This reflects the "buffers" column
of free command line utility on Linux. |
| 66 </blockquote></p><blockquote><i>New in 0.2.0</i><br><i>Availability: <strong>Lin
ux</strong></i> |
| 67 </blockquote><p>psutil.<strong>total_virtmem</strong><font size="3"><strong><tt>
()</tt></strong></font><br> psutil.<strong>avail_virtmem</strong><font size="3">
<strong><tt>()</tt></strong></font><br> psutil.<strong>used_virtmem</strong><fon
t size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return the amount
of total, available and used virtual memory on the system, in bytes.<br>On Linu
x 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 of
<a href="http://msdn.microsoft.com/en-us/library/aa366770(VS.85).aspx" rel="nof
ollow">MEMORYSTATUSEX</a> structure. |
| 68 </blockquote></p> |
| 69 </td> |
| 70 </tr> |
| 71 </table> |
| 72 </div> |
| 73 |
| 74 |
| 75 </body> |
| 76 </html> |
| 77 |
OLD | NEW |