From 3b226d19bb19a87eb565f3e1d16e14f446b56e76 Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 27 Aug 2024 22:25:00 +0000 Subject: deploy: 9b47b98b7c5efce0bf50d57aa5d7e374bcbabf23 --- process/index.html | 241 +++++++++++++++++++++++++++++++++++++++++++ process/lsof.html | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++ process/nice.html | 243 +++++++++++++++++++++++++++++++++++++++++++ process/pgrep.html | 242 +++++++++++++++++++++++++++++++++++++++++++ process/pidstat.html | 253 +++++++++++++++++++++++++++++++++++++++++++++ process/pmap.html | 238 ++++++++++++++++++++++++++++++++++++++++++ process/ps.html | 283 ++++++++++++++++++++++++++++++++++++++++++++++++++ process/pstack.html | 234 +++++++++++++++++++++++++++++++++++++++++ process/taskset.html | 271 ++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 2291 insertions(+) create mode 100644 process/index.html create mode 100644 process/lsof.html create mode 100644 process/nice.html create mode 100644 process/pgrep.html create mode 100644 process/pidstat.html create mode 100644 process/pmap.html create mode 100644 process/ps.html create mode 100644 process/pstack.html create mode 100644 process/taskset.html (limited to 'process') diff --git a/process/index.html b/process/index.html new file mode 100644 index 0000000..fd40579 --- /dev/null +++ b/process/index.html @@ -0,0 +1,241 @@ + + + + + + Process management & inspection - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/lsof.html b/process/lsof.html new file mode 100644 index 0000000..264eef0 --- /dev/null +++ b/process/lsof.html @@ -0,0 +1,286 @@ + + + + + + lsof - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

lsof(8)

+
lsof
+  -r <s> ..... repeatedly execute command ervery <s> seconds
+  -a ......... AND slection filters instead ORing (OR: default)
+  -p <pid> ... filter by <pid>
+  +fg ........ show file flags for file descripros
+  -n ......... don't convert network addr to hostnames
+  -P ......... don't convert network port to service names
+  -i <@h[:p]>. show connections to h (hostname|ip addr) with optional port p
+  -s <p:s> ... in conjunction with '-i' filter for protocol <p> in state <s>
+  -U ......... show unix domain sockets ('@' indicates abstract sock name, see unix(7))
+
+
file flags:
+  R/W/RW ..... read/write/read-write
+  CR ......... create
+  AP ......... append
+  TR ......... truncate
+
+
-s protocols
+  TCP, UDP
+
+-s states (TCP)
+  CLOSED, IDLE, BOUND, LISTEN, ESTABLISHED, SYN_SENT, SYN_RCDV, ESTABLISHED,
+  CLOSE_WAIT, FIN_WAIT1, CLOSING, LAST_ACK, FIN_WAIT_2, TIME_WAIT
+
+-s states (UDP)
+  Unbound, Idle
+
+

Examples

+

File flags

+

Show open files with file flags for process:

+
lsof +fg -p <pid>
+
+

Open TCP connections

+

Show open tcp connections for $USER:

+
lsof -a -u $USER -i TCP
+
+

Note: -a ands the results. If -a is not given all open files matching +$USER and all tcp connections are listed (ored).

+

Open connection to specific host

+

Show open connections to localhost for $USER:

+
lsof -a -u $USER -i @localhost
+
+

Open connection to specific port

+

Show open connections to port :1234 for $USER:

+
lsof -a -u $USER -i :1234
+
+

IPv4 TCP connections in ESTABLISHED state

+
lsof -i 4TCP -s TCP:ESTABLISHED
+
+

List open files in a mounted directory.

+

This may help to find which processes keep devices busy when trying to unmount +and the device is currently busy.

+
# Assuming /proc is a mount point.
+lsof /proc
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/nice.html b/process/nice.html new file mode 100644 index 0000000..8be06db --- /dev/null +++ b/process/nice.html @@ -0,0 +1,243 @@ + + + + + + nice - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

nice(1)

+

Adjust niceness of a new command or running process.

+

Niceness influences the scheduling priority and ranges between:

+
    +
  • -20 most favorable
  • +
  • 19 least favorable
  • +
+
# Adjust niceness +5 for the launched process.
+nice -n 5 yes
+
+# Adjust niceness of running process.
+renice -n 5 -p PID
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/pgrep.html b/process/pgrep.html new file mode 100644 index 0000000..f3d66be --- /dev/null +++ b/process/pgrep.html @@ -0,0 +1,242 @@ + + + + + + pgrep - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

pgrep(1)

+
pgrep [opts] <pattern>
+  -n         only list newest matching process
+  -u <usr>   only show matching for user <usr>
+  -l         additionally list command
+  -a         additionally list command + arguments
+  -x         match exactly
+
+

Debug newest process

+

For example attach gdb to newest zsh process from $USER.

+
gdb -p $(pgrep -n -u $USER zsh)
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/pidstat.html b/process/pidstat.html new file mode 100644 index 0000000..11b2669 --- /dev/null +++ b/process/pidstat.html @@ -0,0 +1,253 @@ + + + + + + pidstat - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

pidstat(1)

+
pidstat [opt] [interval] [cont]
+  -U [user]     show username instead UID, optionally only show for user
+  -r            memory statistics
+  -d            I/O statistics
+  -h            single line per process and no lines with average
+
+

Page fault and memory utilization

+
pidstat -r -p <pid> [interval] [count]
+
+
minor_pagefault: Happens when the page needed is already in memory but not
+                 allocated to the faulting process, in that case the kernel
+                 only has to create a new page-table entry pointing to the
+                 shared physical page (not required to load a memory page from
+                 disk).
+
+major_pagefault: Happens when the page needed is NOT in memory, the kernel
+                 has to create a new page-table entry and populate the
+                 physical page (required to load a memory page from disk).
+
+

I/O statistics

+
pidstat -d -p <pid> [interval] [count]
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/pmap.html b/process/pmap.html new file mode 100644 index 0000000..7e9d3ff --- /dev/null +++ b/process/pmap.html @@ -0,0 +1,238 @@ + + + + + + pmap - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

pmap(1)

+
pmap [opts] <pid>
+    Dump virtual memory map of process.
+    Compared to /proc/<pid>/maps it shows the size of the mappings.
+opts:
+  -p         show full path in the mapping
+  -x         show details (eg RSS usage of each segment)
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/ps.html b/process/ps.html new file mode 100644 index 0000000..7ab5a85 --- /dev/null +++ b/process/ps.html @@ -0,0 +1,283 @@ + + + + + + ps - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

ps(1)

+
ps [opt]
+  opt:
+    --no-header .... do not print column header
+    -o <OUT> ....... comma separated list of output columns
+    -p <PID> ....... only show pid
+    -C <name> ...... only show processes matching name
+    -T ............. list threads
+    --signames ..... use short signames instead bitmasks
+
+
+

Set PS_FORMAT env variable to setup default output columns.

+
+

Frequently used output columns

+
pid        process id
+ppid       parent process id
+pgid       process group id
+tid        thread id
+
+comm       name of process
+cmd        name of process + args (full)
+
+etime      elapsed time (since process started)
+user       user owning process
+thcount    thread count of process
+nice       nice value (-20 highest priority to 19 lowest)
+
+pcpu       cpu utilization (percent)
+pmem       physical resident set (rss) (percent)
+rss        physical memory (in kb)
+vsz        virtual memory (in kb)
+
+sig        mask of pending signals
+sigcatch   mask of caught signals
+sigignore  mask of ignored signals
+sigmask    mask of blocked signals
+
+

Example: Use output for scripting

+
# Print the cpu affinity for each thread of process 31084.
+for tid in $(ps -o tid --no-header -T -p 31084); do
+    taskset -c -p $tid;
+done
+
+

Example: Watch processes by name

+
watch -n1 ps -o pid,pcpu,pmem,rss,vsz,state,user,comm -C fish
+
+

Example: Show signal information

+
# With signal masks.
+ps -o pid,user,sig,sigcatch,sigignore,sigmask,comm -p 66570
+
+# With signal names.
+ps --signames -o pid,user,sig,sigcatch,sigignore,sigmask,comm -p 66570
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/pstack.html b/process/pstack.html new file mode 100644 index 0000000..438a8e6 --- /dev/null +++ b/process/pstack.html @@ -0,0 +1,234 @@ + + + + + + pstack - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

pstack(1)

+
pstack <pid>
+    Dump stack for all threads of process.
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/process/taskset.html b/process/taskset.html new file mode 100644 index 0000000..4a49f60 --- /dev/null +++ b/process/taskset.html @@ -0,0 +1,271 @@ + + + + + + taskset - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

taskset(1)

+

Set cpu affinity for new processes or already running ones.

+
# Pin all (-a) tasks of new command on cores 0,1,2,4.
+taskset -ac 0-2,4 CMD [ARGS]
+
+# Pin all tasks of running PID onto cores 0,2,4.
+taskset -ac 0-5:2 -p PID
+
+

Example

+

Utility script to extract cpu lists grouped by the last-level-cache.

+
import subprocess
+
+res = subprocess.run(["lscpu", "-p=cpu,cache"], capture_output=True, check=True)
+
+LLC2CPU = dict()
+
+for line in res.stdout.decode().splitlines():
+    if line.startswith("#"):
+        continue
+
+    cpu, cache = line.split(",")
+    llc        = cache.split(":")[-1]
+
+    LLC2CPU.setdefault(llc, list()).append(int(cpu))
+
+LLC2RANGE = dict()
+
+for llc, cpus in LLC2CPU.items():
+    first_cpu = cpus[0]
+    prev_cpu  = cpus[0]
+    for cpu in cpus[1:]:
+        if cpu != prev_cpu + 1:
+            LLC2RANGE.setdefault(llc, list()).append(f"{first_cpu}-{prev_cpu}")
+            # New range begins.
+            first_cpu = cpu
+        prev_cpu = cpu
+    # Trailing range.
+    LLC2RANGE.setdefault(llc, list()).append(f"{first_cpu}-{prev_cpu}")
+
+print(LLC2RANGE)
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + -- cgit v1.2.3