Shell equivalents

This page maps psutil’s Python API to the equivalent native terminal commands on each platform. This is useful for understanding what psutil replaces and for cross-checking results.

System-wide functions

CPU

psutil function

Linux

macOS

BSD

Windows

cpu_percent()

top

same

same

cpu_count(logical=True)

nproc

sysctl hw.logicalcpu

sysctl hw.ncpu

cpu_count(logical=False)

lscpu | grep '^Core(s)'

sysctl hw.physicalcpu

cpu_times(percpu=False)

cat /proc/stat | grep '^cpu\s'

systat -vmstat

cpu_times(percpu=True)

cat /proc/stat | grep '^cpu'

systat -vmstat

cpu_times_percent(percpu=False)

mpstat

cpu_times_percent(percpu=True)

mpstat -P ALL

cpu_freq()

cpufreq-info, lscpu | grep "MHz"

sysctl hw.cpufrequency

sysctl dev.cpu.0.freq

systeminfo

cpu_stats()

vmstat -s, sysctl vm.stats.sys

getloadavg()

uptime

same

same

Memory

psutil function

Linux

macOS

BSD

Windows

virtual_memory()

free, vmstat, cat /proc/meminfo

vm_stat

vmstat -s, sysctl vm.stats

systeminfo

swap_memory()

free, vmstat, swapon

sysctl vm.swapusage

vmstat -s, swapinfo

heap_info()

heap_trim()

Disks

psutil function

Linux

macOS

BSD

Windows

disk_usage()

df

same

same

fsutil volume diskfree C:\

disk_partitions()

mount, findmnt

mount

mount

disk_io_counters()

iostat -dx

iostat

iostat -x

Network

psutil function

Linux

macOS

BSD

Windows

net_connections()

netstat -anp, ss, lsof -nP -i -U

netstat -anp

netstat -an

netstat -an

net_if_addrs()

ifconfig, ip addr

ifconfig

ifconfig

ipconfig, systeminfo

net_io_counters()

netstat -i, ifconfig, ip -s link

netstat -i

netstat -i

netstat -e

net_if_stats()

ifconfig, ip -br link, ip link

ifconfig

ifconfig

netsh interface show interface

Sensors

psutil function

Linux

macOS

BSD

Windows

sensors_temperatures()

sensors

sysctl dev.cpu.*.temperature

sensors_fans()

sensors

sysctl dev.cpu.*.fan

sensors_battery()

acpi -b

pmset -g batt

apm -b

Other

psutil function

Linux

macOS

BSD

Windows

boot_time()

uptime, who -b

sysctl kern.boottime

sysctl kern.boottime

systeminfo

users()

who -a, w

same

same

pids()

ps -A -eo pid

same

same

tasklist

pid_exists()

kill -0 PID

same

same

Process methods

Assuming p = psutil.Process().

Identity

psutil method

Linux

macOS

BSD

Windows

p.name()

ps -o comm -p PID

same

procstat -b PID

p.exe()

readlink /proc/pid/exe

lsof -p PID

procstat -b PID

p.cmdline()

ps -o args -p PID

same

procstat -c PID

p.status()

ps -o stat -p PID

same

same

p.create_time()

ps -o lstart -p PID

same

same

p.is_running()

kill -0 PID

same

same

p.environ()

xargs -0 -a /proc/pid/environ

procstat -e PID

p.cwd()

pwdx PID

lsof -p PID -a -d cwd

Process tree

psutil method

Linux

macOS

BSD

Windows

p.ppid()

ps -o ppid= -p PID

same

same

p.parent()

ps -p $(ps -o ppid= -p PID)

same

same

p.parents()

pstree -s PID

same

same

p.children(recursive=False)

pgrep -P PID

same

same

p.children(recursive=True)

pstree -p PID

same

same

Credentials

psutil method

Linux

macOS

BSD

Windows

p.uids()

ps -o uid,ruid,suid -p PID

same

procstat -s PID

p.gids()

ps -o gid,rgid,sgid -p PID

same

procstat -s PID

p.username()

ps -o user -p PID

same

same

p.terminal()

ps -o tty -p PID

same

same

CPU / scheduling

psutil method

Linux

macOS

BSD

Windows

p.cpu_percent()

ps -o %cpu -p PID

same

same

p.cpu_times()

ps -o cputime -p PID

same

procstat -r PID

p.cpu_num()

ps -o psr -p PID

p.num_ctx_switches()

pidstat -w -p PID

procstat -r PID

p.cpu_affinity()

taskset -p PID

cpuset -g -p PID

p.cpu_affinity(CPUS)

taskset -p MASK PID

cpuset -s -p PID -l CPUS

p.ionice()

ionice -p PID

p.ionice(CLASS)

ionice -c CLASS -p PID

p.nice()

ps -o nice -p PID

same

same

p.nice(VALUE)

renice -n VALUE -p PID

same

same

p.rlimit(RES)

prlimit --pid PID

procstat rlimit PID

p.rlimit(RES, LIMITS)

prlimit --pid PID --RES=SOFT:HARD

Memory

psutil method

Linux

macOS

BSD

Windows

p.memory_info()

ps -o rss,vsz -p PID

same

same

p.memory_info_ex()

cat /proc/pid/status

p.memory_percent()

ps -o %mem -p PID

same

same

p.memory_maps()

pmap PID

vmmap PID

procstat -v PID

p.memory_footprint()

smem, smemstat

p.page_faults()

ps -o maj_flt,min_flt -p PID

ps -o faults -p PID

procstat -r PID

Threads

psutil method

Linux

macOS

BSD

Windows

p.num_threads()

ps -o nlwp -p PID

same

same

p.threads()

ps -T -p PID

Files and connections

psutil method

Linux

macOS

BSD

Windows

p.net_connections()

ss -p, lsof -p PID -i

lsof -p PID -i

netstat -ano | findstr PID

p.open_files()

lsof -p PID

same

procstat -f PID, fstat

handle.exe -p PID

p.io_counters()

cat /proc/pid/io

p.num_fds()

ls /proc/pid/fd | wc -l

p.num_handles()

Signals

psutil method

Linux

macOS

BSD

Windows

p.send_signal()

kill -SIG PID

same

same

p.suspend()

kill -STOP PID

same

same

p.resume()

kill -CONT PID

same

same

p.terminate()

kill -TERM PID

same

same

taskkill /PID PID

p.kill()

kill -KILL PID

same

same

taskkill /F /PID PID

p.wait()

tail --pid=PID -f /dev/null

lsof -p PID +r 1

pwait PID