Useful Linux Commands for System Management

I often find myself using these commands to get detailed information about a system’s hardware or manage system’s resources. I will probably update this list as I think of more.

Get Process ID

To find the process ID of a specific process, use the following command:

1
pgrep <query>

Replace <query> with the query or name of the process you are looking for. In the following sections, we’ll use $PID to represent the process ID you obtain from this command.

1
PID=$(pgrep <query>)

Get all TIDs in a process

1
ps -mo tid -p $PID | grep -v TID | grep -v -

pidstat

pidstat is a command-line tool that reports detailed information about the running processes. You can get a comprehensive pidstat report by running the following commands:

To install:

For Debian/Ubuntu:

1
apt install sysstat

For Alpine Linux:

1
apk add sysstat

To get a detailed report for a given process:

1
pidstat -durRtsw --human -h -p $PID 1

tuna

tuna is a utility for managing threads and CPU cores. You can isolate a specific CPU core or move a thread to a different core using the following commands:

To isolate a CPU:

1
sudo tuna -c CPU# -i

To move a thread to a specific CPU:

1
sudo tuna -t $TID -c CPU# -m

Replace CPU# with the CPU core number and $TID with the thread ID.

CPU and Topology Details

To gather detailed information about your system’s CPU, you can use the following commands:

1
2
3
lscpu
lshw -C cpu
cat /proc/cpuinfo

lstopo is a command-line tool that provides a graphical representation of your system’s hardware layout.

To install it, run:

For Debian/Ubuntu:

1
apt install hwloc

For Alpine Linux:

1
apk add hwloc-tools

To get CPU topography:

1
lstopo-no-graphics --no-io --of txt

Memory Details

To get detailed information about your system’s memory, use the following commands:

1
2
3
lsmem
lshw -C memory
cat /proc/meminfo

numactl

numactl is a utility for managing Non-Uniform Memory Access (NUMA) systems.

To install it and check your system’s NUMA hardware information, run:

For Debian/Ubuntu:

1
apt install numactl

For Alpine Linux:

1
apk add numactl

To get hardware information:

1
numactl --hardware

Run process on a specific numa node:

1
numactl -C 0 -m 0 <command>

Watch Interrupts

To monitor the interrupts in real-time, use the following command:

1
watch -n 1 cat /proc/interrupts

Taskset

taskset allows you to set or retrieve the CPU affinity of a process.

1
taskset -pc CPUID $TID

Replace CPUID with the CPU core number and $TID with the thread ID.