psutil
The installation method and official documents of the module are detailed in: https://psutil.readthedocs.io/en/latest/
Meaning of each process statistics
pid
: PID of the process
Return the pid of the process.
cpu_num
: CPU core running the current process
Returns the CPU cores on which the current process is running. The return value will be less than or equal to the number of logical cores of the CPU.
cpu_percent
: Process CPU utilization
Returns the CPU utilization of a process. This percentage can also be greater than 100% if the process runs multiple threads on different CPUs.
- When the parameter
interval > 0.0
, it will block the duration ofinterval
and count the CPU utilization during this period; - When the parameter
interval == 0 or interval is None
- If called for the first time, it will return meaningless
0.0
; - If it is not the first call, the CPU utilization during the period from the last call will be counted (it is recommended to have at least 0.1 seconds between calls)
- If called for the first time, it will return meaningless
cpu_times
: cumulative process CPU time
Returns the cumulative process CPU time in seconds. in:
user
: CPU time in user mode;system
: CPU time in kernel mode;children_user
: CPU time of all child processes in user mode;children_system
: the CPU time of the kernel state of all child processes;iowait
: Time to wait for blocking I/O to complete (this value is not included in user time and system time)
create_time
: process creation time
Returns the process creation time (unit: timestamp). The return value will be cached after the first call.
name
: process name
Returns the process name.
ppid
: the parent process of the process
Returns the parent process of the process.
status
: the status of the process
Contains the following process status, the explanation in the status comes from ChatGPT:
Process Status | Process Code | Explanation |
---|---|---|
STATUS_RUNNING | running |
The process is running or preparing to run. |
STATUS_SLEEPING | sleeping |
The process is in a sleeping state, waiting for an event to occur. |
STATUS_DISK_SLEEP | disk-sleep |
The process is waiting for disk I/O operations to complete. |
STATUS_STOPPED | stopped |
The process has stopped, but has not been terminated. |
STATUS_TRACING_STOP | tracing-stop |
The process has been stopped for tracing and debugging purposes. |
STATUS_ZOMBIE | zombie |
The process has exited, but its parent process has not reclaimed its resources. |
STATUS_DEAD | dead |
The process has exited and its resources have been reclaimed. |
STATUS_WAKE_KILL | wake-kill |
The process is waiting to be killed. |
STATUS_WAKING | waking |
The process is waking from sleep. |
STATUS_IDLE | idle |
The process is idle. |
STATUS_LOCKED | locked |
The process is locked and cannot run or receive signals. |
STATUS_WAITING | waiting |
The process is waiting for an event to occur. |
STATUS_SUSPENDED | suspended |
The process is suspended and no longer accepts any input or output. |
STATUS_PARKED | parked |
The process temporarily sleeps and wakes up again after certain conditions are met. |
terminal
: the terminal associated with the process
Returns the terminal associated with the current process.
num_ctx_switches
: cumulative number of context switches
Returns the accumulated total number of voluntary conetxt switches and total number of involuntary context switches.
- voluntary context switches: accessing a resource that is already in use and thus has to be suspended
- involuntary context switches: own time slice runs out or is replaced by a higher priority thread
num_threads
: the number of threads used by the current process
Returns the number of threads used by the current process.
username
: username
Returns the username of the owner of the current process.
memory_full_info
: return memory usage information
Return memory usage information. in:
Indicator name | description |
---|---|
rss (Resident Set Size) |
The non-swap physical memory used by the process (same as the RES column of the TOP command) |
vms (Virtual Memory Size) |
The virtual memory used by the process (with the VIRT of the TOP command code> column) |
shared |
Memory that may be shared with other processes (same as TOP command’s SHR column is the same) |
text |
The memory occupied by the executable code Size (same as CODE column of TOP command) |
data |
Refers to the size of physical memory excluding executable code (same as DATA column of TOP command) |
lib |
Memory used by shared library files |
dirty |
Number of dirty pages, refers to the number of pages that have not been synchronized to disk |
uss (Unique Set Size) |
process exclusive The size of the memory that will be freed if the process is now terminated. |
pss (Proportional Set Size) |
The amount of memory shared with other processes, the amount is divided equally during calculation to all processes that share memory. For example: If a process has 10MB exclusively and shares 10MB with another process, its PSS is 15MB. |
swap |
The memory size that has been swapped to the hard disk |