Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: third_party/psutil/docs/documentation.html

Issue 8774018: Add psutil build step to fix pyauto media issues. Upgrade psutil to 0.4.0. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Disable Mac builds. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 <!-- saved from url=(0066)http://code.google.com/p/psutil/wiki/DocumentationDev? show=content --> 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"> 3 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4 <title>DocumentationDev</title> 4 <title>DocumentationDev</title>
5 <script src="./documentation_files/googleapis.client__plusone.js"></script></he ad> 5 </head>
6 <body> 6 <body>
7 7
8 8
9 9
10 10
11 11
12 <div> 12 <div>
13 <table> 13 <table>
14 <tbody><tr> 14 <tbody><tr>
15 15
16 16
17 <td style="vertical-align:top; padding-left:5px"> 17 <td style="vertical-align:top; padding-left:5px">
18 18
19 <div id="wikicontent"> 19 <div id="wikicontent">
20 <div class="vt" id="wikimaincol"> 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). 21 <h1><a name="API_Reference"></a>API Reference<a href="http://code.google.com/p/p sutil/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<a href="http://code.google.com/p/psutil/w /edit/NoSuchProcess">?</a></strong><font size="3"><strong><tt>(</tt></strong></f ont><i>pid, name=None, msg=None</i><font size="3"><strong><tt>)</tt></strong></f ont> </p><blockquote>Raised when no process with the given PID is found in the c urrent 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. 22 </blockquote><p></p><p>psutil.<strong>AccessDenied<a href="http://code.google.co m/p/psutil/w/edit/AccessDenied">?</a></strong><font size="3"><strong><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 perform 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. 23 </blockquote><p></p><p>psutil.<strong>TimeoutExpired<a href="http://code.google. com/p/psutil/w/edit/TimeoutExpired">?</a></strong><font size="3"><strong><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)</tt> if timeo ut expires and process is still alive.
24 </blockquote><p></p><blockquote><i><strong>New in 0.2.1</strong></i> 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. 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">&gt;&gt;&gt; import os, psutil, datetime 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">&gt;&gt;&gt; import os, psutil, datetime
27 &gt;&gt;&gt; p = psutil.Process(os.getpid()) 27 &gt;&gt;&gt; p = psutil.Process(os.getpid())
28 &gt;&gt;&gt; p.create_time 28 &gt;&gt;&gt; p.create_time
29 1307289803.47 29 1307289803.47
30 &gt;&gt;&gt; datetime.datetime.fromtimestamp(p.create_time).strftime("%Y-%M-%d % H:%M") 30 &gt;&gt;&gt; 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> 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> 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> 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> 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">&gt;&gt;&gt; import psutil, os 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">&gt;&gt;&gt; import psutil, os
36 &gt;&gt;&gt; p = psutil.Process(os.getpid()) 36 &gt;&gt;&gt; p = psutil.Process(os.getpid())
37 &gt;&gt;&gt; p.status 37 &gt;&gt;&gt; p.status
38 0 38 0
39 &gt;&gt;&gt; p.status == psutil.STATUS_RUNNING 39 &gt;&gt;&gt; p.status == psutil.STATUS_RUNNING
40 True 40 True
41 &gt;&gt;&gt; str(p.status) 41 &gt;&gt;&gt; str(p.status)
42 'running' 42 'running'
43 &gt;&gt;&gt;</pre></ul><blockquote><i><strong>New in 2.1</strong></i> 43 &gt;&gt;&gt;</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">&gt;&gt;&gt; p = psutil.Process(os.getpid()) 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">&gt;&gt;&gt; p = psutil.Process(os.getpid())
45 &gt;&gt;&gt; p.nice 45 &gt;&gt;&gt; p.nice
46 0 46 0
47 &gt;&gt;&gt; p.nice = 10 # set/change process priority 47 &gt;&gt;&gt; p.nice = 10 # set/change process priority
48 &gt;&gt;&gt; p.nice 48 &gt;&gt;&gt; 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: 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">&gt;&gt; p.nice = psutil.HIGH_ PRIORITY_CLASS</pre> 50 </blockquote><blockquote><pre class="prettyprint">&gt;&gt; p.nice = psutil.HIGH_ PRIORITY_CLASS</pre>
51 </blockquote><blockquote><i><strong>New in 2.1</strong></i> 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> 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, Fr eeBSD</i><br>
53 <i><strong>Changed in 0.4.0:</strong> added FreeBSD support</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">&gt;&gt;&gt; p.get_i o_counters() 54 </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">&gt;&gt;&gt; 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 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>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">&gt;&gt;&gt; import psutil, os 57 </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">&gt;&gt;&gt; import psutil, os
57 &gt;&gt;&gt; p = psutil.Process(os.getpid()) 58 &gt;&gt;&gt; p = psutil.Process(os.getpid())
58 &gt;&gt;&gt; p.set_ionice(psutil.IOPRIO_CLASS_IDLE) 59 &gt;&gt;&gt; p.set_ionice(psutil.IOPRIO_CLASS_IDLE)
59 &gt;&gt;&gt;</pre></ul><blockquote><i><strong>New in 2.1</strong></i><br><i><str ong>Availability:</strong> Linux</i> 60 &gt;&gt;&gt;</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_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 &gt; 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_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 &gt; 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. Example: </li><pre class="prettyprint">&gt;&gt;&gt; import psutil, os
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">&gt;&gt;&gt; import psutil, os 63 &gt;&gt;&gt; p = psutil.Process(os.getpid())
64 &gt;&gt;&gt; # blocking
65 &gt;&gt;&gt; p.get_cpu_percent(interval=1)
66 2.0
67 &gt;&gt;&gt; # non-blocking (percentage since last call)
68 &gt;&gt;&gt; p.get_cpu_percent(interval=0)
69 2.9
70 &gt;&gt;&gt;</pre></ul><blockquote><i><strong>Changed in 0.2.0:</strong> interva l parameter was added</i>
71 </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. Example: </li><pre class="prettyprint">&gt;&gt;&gt; i mport psutil, os
63 &gt;&gt;&gt; f = open('file.ext', 'w') 72 &gt;&gt;&gt; f = open('file.ext', 'w')
64 &gt;&gt;&gt; p = psutil.Process(os.getpid()) 73 &gt;&gt;&gt; p = psutil.Process(os.getpid())
65 &gt;&gt;&gt; p.get_open_files() 74 &gt;&gt;&gt; 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> 75 [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><br>
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: 76 <i><strong>Changed in 0.4.1:</strong> FreeBSD implementation rewritten in C; no longer requiring lsof.</i>
77 </blockquote><ul><li><strong>get_connections</strong><font size="3"><strong><tt> (</tt></strong></font><i>kind='inet'</i><font size="3"><strong><tt>)</tt></stron g></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#col lections.namedtuple" rel="nofollow">namedtuples</a>. Every namedtuple provides 6 attributes:<br><br> </li><ul><li><strong>fd</strong>: the socket file descripto r. This can be passed to <a href="http://docs.python.org/library/socket.html#soc ket.fromfd" rel="nofollow">socket.fromfd</a> to obtain a usable socket object. T his is only available on UNIX; on Windows <tt>-1</tt> is always returned.<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_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 type, either <a h ref="http://docs.python.org/library/socket.html#socket.SOCK_STREAM" rel="nofollo w">SOCK_STREAM</a> or <a href="http://docs.python.org/library/socket.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. Whe n the remote endpoint is not connected the tuple is empty. <br> </li><li><strong >status</strong>: a string representing the TCP connections status. String value s 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 al l platforms. For UDP sockets this is always going to be an empty string.<br> </l i></ul></ul><blockquote>The kind parameter is a string which filters for connect ions that fit the following criteria:
78 </blockquote><p><table class="wikitable"><tbody><tr><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Kind value</strong> </td><td style="border: 1px s olid #ccc; padding: 5px;"> <strong>Connections using</strong> </td></tr> <t r><td style="border: 1px solid #ccc; padding: 5px;"> inet </td><td style ="border: 1px solid #ccc; padding: 5px;"> IPv4 and IPv6 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> inet4 </td><td style="bord er: 1px solid #ccc; padding: 5px;"> IPv4 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> inet6 </td><td style="border: 1px solid # ccc; padding: 5px;"> IPv6 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> tcp </td><td style="border: 1px solid #ccc; padding: 5 px;"> TCP </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> tcp4 </td><td style="border: 1px solid #ccc; padding: 5px;"> TCP o ver IPv4 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> tcp6 </td><td style="border: 1px solid #ccc; padding: 5px;"> TCP over IP v6 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> udp </td><td style="border: 1px solid #ccc; padding: 5px;"> UDP </td></tr> <t r><td style="border: 1px solid #ccc; padding: 5px;"> udp4 </td><td style ="border: 1px solid #ccc; padding: 5px;"> UDP over IPv4 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> udp6 </td><td style="bord er: 1px solid #ccc; padding: 5px;"> UDP over IPv6 </td></tr> <tr><td style= "border: 1px solid #ccc; padding: 5px;"> all </td><td style="border: 1p x solid #ccc; padding: 5px;"> the sum of all the possible families and prot ocols </td></tr> </tbody></table></p><blockquote>Example:
68 <pre class="prettyprint">&gt;&gt;&gt; p = psutil.Process(1694) 79 <pre class="prettyprint">&gt;&gt;&gt; p = psutil.Process(1694)
69 &gt;&gt;&gt; p.name 80 &gt;&gt;&gt; p.name
70 'firefox' 81 'firefox'
71 &gt;&gt;&gt; p.get_connections() 82 &gt;&gt;&gt; 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'), 83 [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'), 84 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'), 85 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> 86 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> 87 </blockquote><blockquote><i><strong>Changed in 0.2.1:</strong> OSX implementatio n rewritten in C; no longer requiring lsof.</i><br>
88 <i><strong>Changed in 0.4.0:</strong> added 'kind' parameter.</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> 89 </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> 90 </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><br>
91 <i><strong>Changed in 0.4.0</strong>: timeout=0 can now be used to make wait() r eturn immediately (non blocking)</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>. 92 </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">&gt;&gt;&gt; import psutil 93 <pre class="prettyprint">&gt;&gt;&gt; import psutil
81 &gt;&gt;&gt; from subprocess import PIPE 94 &gt;&gt;&gt; from subprocess import PIPE
82 &gt;&gt;&gt; p = psutil.Popen(["/usr/bin/python", "-c", "print 'hi'"], stdout=PI PE) 95 &gt;&gt;&gt; p = psutil.Popen(["/usr/bin/python", "-c", "print 'hi'"], stdout=PI PE)
83 &gt;&gt;&gt; p.name 96 &gt;&gt;&gt; p.name
84 'python' 97 'python'
85 &gt;&gt;&gt; p.uids 98 &gt;&gt;&gt; p.uids
86 user(real=1000, effective=1000, saved=1000) 99 user(real=1000, effective=1000, saved=1000)
87 &gt;&gt;&gt; p.username 100 &gt;&gt;&gt; p.username
88 'giampaolo' 101 'giampaolo'
89 &gt;&gt;&gt; p.communicate() 102 &gt;&gt;&gt; p.communicate()
90 ('hi\n', None) 103 ('hi\n', None)
91 &gt;&gt;&gt; p.wait(timeout=2) 104 &gt;&gt;&gt; p.wait(timeout=2)
92 0 105 0
93 &gt;&gt;&gt;</pre></blockquote><blockquote><i><strong>New in 0.2.1</strong></i> 106 &gt;&gt;&gt;</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 . 107 </blockquote><hr><h2><a name="System_related_functions"></a>System related funct ions<a href="http://code.google.com/p/psutil/wiki/DocumentationDev?show=content# System_related_functions" class="section_anchor"></a></h2><h3><a name="Processes "></a>Processes<a href="http://code.google.com/p/psutil/wiki/DocumentationDev?sh ow=content#Processes" class="section_anchor"></a></h3><p>psutil.<strong>get_pid_ list</strong><font size="3"><strong><tt>()</tt></strong></font><br> </p><blockqu ote>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. 108 </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. 109 </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 &gt; 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. 110 </blockquote><p></p><hr><h3><a name="CPU"></a>CPU<a href="http://code.google.com /p/psutil/wiki/DocumentationDev?show=content#CPU" class="section_anchor"></a></h 3><p>psutil.<strong>cpu_percent</strong><font size="3"><strong><tt>(</tt></stron g></font><i>interval=0.1, percpu=False</i><font size="3"><strong><tt>)</tt></str ong></font><br> </p><blockquote>Return a float representing the current system-w ide CPU utilization as a percentage. When interval is &gt; 0.0 compares system C PU times elapsed before and after the interval (blocking). When interval is 0.0 or None compares system CPU times elapsed since last call or module import, retu rning immediately. In this case is recommended for accuracy that this function b e called with at least 0.1 seconds between calls.<br>When <i>percpu</i> is True returns a list of floats representing the utilization as a percentage for each C PU. First element of the list refers to first CPU, second element to second CPU and so on. The order of the list is consistent across calls.
98 </blockquote><p></p><pre class="prettyprint">&gt;&gt;&gt; # blocking, system-wid e 111 </blockquote><p></p><pre class="prettyprint">&gt;&gt;&gt; # blocking, system-wid e
99 &gt;&gt;&gt; psutil.cpu_percent(interval=1) 112 &gt;&gt;&gt; psutil.cpu_percent(interval=1)
100 2.0 113 2.0
101 &gt;&gt;&gt; 114 &gt;&gt;&gt;
102 &gt;&gt;&gt; # blocking, per-cpu 115 &gt;&gt;&gt; # blocking, per-cpu
103 &gt;&gt;&gt; psutil.cpu_percent(interval=1, percpu=True) 116 &gt;&gt;&gt; psutil.cpu_percent(interval=1, percpu=True)
104 [2.0, 1.0] 117 [2.0, 1.0]
105 &gt;&gt;&gt; 118 &gt;&gt;&gt;
106 &gt;&gt;&gt; # non-blocking (percentage since last call) 119 &gt;&gt;&gt; # non-blocking (percentage since last call)
107 &gt;&gt;&gt; psutil.cpu_percent(interval=0) 120 &gt;&gt;&gt; psutil.cpu_percent(interval=0)
(...skipping 12 matching lines...) Expand all
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. 133 </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">&gt;&gt;&gt; psutil.phymem_usage() 134 <p></p><pre class="prettyprint">&gt;&gt;&gt; psutil.phymem_usage()
122 usage(total=4153868288, used=2854199296, free=1299668992, percent=34.6)</pre><i> <strong>New in 0.3.0</strong></i> 135 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. 136 </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">&gt;&gt;&gt; psutil.virtmem_usage() 137 <p></p><pre class="prettyprint">&gt;&gt;&gt; psutil.virtmem_usage()
125 usage(total=2097147904, used=4096, free=2097143808, percent=0.0)</pre><i><strong >New in 0.3.0</strong></i> 138 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. 139 </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> 140 </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. 141 </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> 142 </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. 143 </blockquote><hr><h3><a name="Disks"></a>Disks<a href="http://code.google.com/p/ psutil/wiki/DocumentationDev?show=content#Disks" class="section_anchor"></a></h3 ><p>psutil.<strong>disk_partitions</strong><font size="3"><strong><tt>(</tt></st rong></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 in cluding device, mount point and filesystem type, similarly to "df" command on po six. <br>If <i>all</i> parameter is False return physical devices only (e.g. har d disks, cd-rom drives, USB keys) and ignore all others (e.g. memory partitions such as <a href="http://www.cyberciti.biz/tips/what-is-devshm-and-its-practical- usage.html" rel="nofollow">/dev/shm</a>).<br> Namedtuple's 'fstype' field is a s tring which varies depending on the platform. <br>On Linux it can be one of the values found in /proc/filesystems (e.g. 'ext3' for an ext3 hard drive o 'iso9660 ' for the CD-ROM drive). <br>On Windows it is determined via <a href="http://msd n.microsoft.com/en-us/library/aa364939(v=vs.85).aspx" rel="nofollow">GetDriveTyp e</a> and can be either "removable", "fixed", "remote", "cdrom", "unmounted" or "ramdisk". <br>On OSX and FreeBSD it is retrieved via <a href="http://www.manpag ez.com/man/2/getfsstat/" rel="nofollow">getfsstat(2)</a>. <br>See <a href="http: //psutil.googlecode.com/svn/trunk/examples/disk_usage.py" rel="nofollow">example s/disk_usage.py</a> script providing an example usage.
131 <p></p><pre class="prettyprint">&gt;&gt;&gt; psutil.get_partitions() 144 <p></p><pre class="prettyprint">&gt;&gt;&gt; psutil.disk_partitions()
132 [partition(device='/dev/sda3', mountpoint='/', fstype='ext4'), 145 [partition(device='/dev/sda3', mountpoint='/', fstype='ext4'),
133 partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')] 146 partition(device='/dev/sda7', mountpoint='/home', fstype='ext4')]
134 &gt;&gt;&gt;</pre></blockquote><blockquote><i><strong>New in 0.3.0</strong></i> 147 &gt;&gt;&gt;</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. 148 </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">&gt;&gt;&gt; psutil.disk_usage('/') 149 <p></p><pre class="prettyprint">&gt;&gt;&gt; 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> 150 usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)</pre>< /blockquote><blockquote><i><strong>New in 0.3.0</strong></i>
151 </blockquote><p>psutil.<strong>disk_io_counters</strong><font size="3"><strong>< tt>(</tt></strong></font><i>perdisk=False</i><font size="3"><strong><tt>)</tt></ strong></font><br> </p><blockquote>Return system disk I/O statistics as a namedt uple including the following attributes:
152 <ul><li><strong>read_count</strong>: number of reads </li><li><strong>write_coun t</strong>: number of writes </li><li><strong>read_bytes</strong>: number of byt es read </li><li><strong>write_bytes</strong>: number of bytes written </li><li> <strong>read_time</strong>: time spent reading from disk (in milliseconds) </li> <li><strong>write_time</strong>: time spent writing to disk (in milliseconds) </ li></ul></blockquote><p></p><blockquote>If perdisk is True return the same infor mation for every physical disk installed on the system as a dictionary with part ition ames as the keys and the namedutuple described above as the values.
153 </blockquote><pre class="prettyprint">&gt;&gt;&gt; psutil.disk_io_counters()
154 iostat(read_count=8141, write_count=2431, read_bytes=290203, write_bytes=537676, read_time=5868, write_time=94922)</pre><blockquote><i><strong>New in 0.4.0</str ong></i>
155 </blockquote><hr><h3><a name="Network"></a>Network<a href="http://code.google.co m/p/psutil/wiki/DocumentationDev?show=content#Network" class="section_anchor"></ a></h3><p>psutil.<strong>network_io_counters</strong><font size="3"><strong><tt> (</tt></strong></font><i>pernic=False</i><font size="3"><strong><tt>)</tt></stro ng></font><br> </p><blockquote>Return network I/O statistics as a namedtuple inc luding the following attributes:
156 <ul><li><strong>bytes_sent</strong>: number of bytes sent </li><li><strong>bytes _recv</strong>: number of bytes received </li><li><strong>packets_sent</strong>: number of packets sent </li><li><strong>packets_recv</strong>: number of packet s received </li></ul></blockquote><p></p><blockquote>If pernic is True return th e same information for every network interface installed on the system as a dict ionary with network interface names as the keys and the namedtuple described abo ve as the values.
157 </blockquote><pre class="prettyprint">&gt;&gt;&gt; psutil.network_io_counters()
158 iostat(bytes_sent=1270374, bytes_recv=7828365, packets_sent=9810, packets_recv=1 1794)</pre><blockquote><i><strong>New in 0.4.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. 159 </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. 160 </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. 161 </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> 162 </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. 163 </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> 164 </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. 165 </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> 166 </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. 167 </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> 168 </blockquote><p></p><blockquote><i><strong>New in 0.2.1</strong></i><br><i><stro ng>
148 </strong></i></blockquote> 169 </strong></i></blockquote>
149 </div> 170 </div>
150 </div> 171 </div>
151 </td></tr><tr> 172 </td></tr><tr>
152 </tr></tbody></table> 173 </tr></tbody></table>
153 </div> 174 </div>
154 175
155 176
156 177
157 178
158 <script type="text/javascript" src="./documentation_files/dit_scripts.js"></scri pt> 179 <script src="./DocumentationDev_files/googleapis.client__plusone.js"></script><s cript type="text/javascript" src="./DocumentationDev_files/dit_scripts.js"></scr ipt>
159 180
160 181
161 <script type="text/javascript" src="./documentation_files/plusone.js"> 182 <script type="text/javascript">
183 _fetchOptions(
184 "", "psutil", "wikiOptions",
185 codesite_token, 1319284146);
186 _onload();
187 </script>
188
189 <script type="text/javascript" src="./DocumentationDev_files/plusone.js">
162 </script> 190 </script>
163 191
164 192
165 193
166 194
167 </body></html> 195 </body></html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698