System and processes

List the processes by memory

List the five processes that use the most memory.

processes |> sort memory order: desc |> first 5
pid
ps aux --sort=-%mem | head -6

Find a process by name

Find the processes whose name matches a pattern.

processes /node/
node

Show who listens on a port

Show the process that listens on port 8080.

ports state: listen |> filter port == 8080
8080
ss -ltnp | grep :8080

Stop a process

Stop the process with a given identifier.

processes pid: 4132 |> stop
4132

Kill a process that ignores termination

Kill a process that does not react to the termination signal.

processes pid: 4132 |> stop signal: kill
4132

Show the disks

Show the mounted volumes and their free space.

disks
free
df -h

Show the host

Show the operating system, the user and the programs that are installed.

host programs: ["git", "python3", "node"] versions: true
git

Show the environment variables

Show the environment variables of the process whose name contains PATH.

environment /PATH/
PATH

Find the program in the search path

Find where a program is installed.

program.find "git"
git

Find the processes that hold a file open

Find the processes that keep a file open.

open_files "/home/user/app/app.log"
pid

Read the system log

Read the 50 latest error events of the system log.

logs level: error limit: 50
error

Read the log of one unit

Read the log of one service unit since one hour ago.

logs unit: "nginx" since: ago(1h)
nginx

Show the accounts

List the user accounts of the host.

accounts kind: user
user

Suspend a process

Suspend a process until it is resumed.

processes pid: 4132 |> suspend
4132

Resume a process

Resume a suspended process.

processes pid: 4132 |> resume
4132

List the processes of an account

List the processes that run for one account.

processes user: "deploy"
deploy
ps -u deploy

Show the working directory of processes

Show the working directories of the processes whose name matches a pattern.

processes /node/ cwd: true
node

Show the UDP ports

Show all ports that use the UDP protocol, not only the listening ones.

ports state: all protocol: udp
udp
ss -uanp

Find the disk with the least free space

Show the volume with the least free space.

disks |> sort free order: asc |> first 1
free
df -h --output=source,avail | sort -h -k2 | head -2

Show the variables of the account

Show the environment variable PATH as it is set for the account, not for the session.

environment "PATH" scope: user
PATH

Search the warnings of the system log

Show the warnings of the last day that mention a timeout.

logs level: warning message: /timeout/ since: ago(24h)
timeout
journalctl -p warning --since '-1 day' | grep -i timeout

Read a window of the log of a unit

Read the log of a unit between two points in time.

logs unit: "sshd" since: ago(2h) until: ago(1h)
sshd

Find an installed program by a keyword

Search the path, the packages and the applications for programs that handle JSON.

program.search "json" source: [path, package] limit: 10
json

Read the description of a program

Read the card of a program with its usage guide.

program.describe "jq" include_guide: true
jq

Show the versions of installed programs

Show the locations and versions of several programs.

program.find ["git", "make"] versions: true
git

Stop a process after a grace period

Terminate a process and kill it when it does not exit within five seconds.

processes /^runaway$/ |> stop grace: 5s
runaway

Source file on GitHub: docs/cookbook/system-and-processes.md