Proccess
Look process by name
pgrep
Kill process by name
pkill <process name>
killall <process name>
Process tree
pstree
Show what process use device
fuser -m /mnt
Kill all user processes
killall -u user
Process information pseudo-filesystem
/proc
Show information about PID
top -p <PID>
Show namespaces
ls -l /prod/proc/<PID>/ns/
Show maps
cat /proc/<PID>/uid_map
cat /proc/<PID>/gid_map
Run in namespaces
unshare <parameters> <program>
Show namespaces
lsns
ls -al /proc/<PID>/ns
Show cgroups
cat /proc/<PID>/cgroup
Execute program in namespace
nsenter --target <PID> <parameters> <program>
Pressure Stall Information 10s 60s 300s
/proc/pressure/<cpu|io|irq|memory>
Hide processes (fstab)
proc /proc hidepid=<0-2>, gid=<group> ...
Show maximum of open files
cat /proc/sys/fs/file-max
Show open files of process
ls -l /proc/<PID>/fd/
lsof | grep <PID>
Show a list of user processes
lsof -u <user_name>
Show open files of process
lsof -p <pid>
Show openfiles of command
lsof -c <command>
Show what process use port
lsof -i :<port_number>
Show open files in directory
lsof +D <path_to_directory>
Show the number of open files on your system
lsof | wc -l
lsof <path to dir>
Show limits of process start by user
cat /proc/<pid>/limits
Show maximum of objects inotify per user
/proc/sys/fs/inotify/max_user_instances
Show maximum of watch files and directories per object inotify
/proc/sys/fs/inotify/max_user_watches
Show maximum of events in queued
/proc/sys/fs/inotify/max_queued_events
Show shell process of user limits
ulimit -a
Show settings
sysctl -a
Accept changes
sysctl -p
Change process limits
prlimit --pid PID --nofile=1024:1024
IO priority
ionice -c3 coommand
Start with priority
nice -n 15 command
Change the priority
renice renice -n 15 -p pid
Sort by RAM
ps aux | sort -nk 4
ps aux --sort=%mem | grep -v 'root' | head -n 35
Sort by CPU
ps aux | sort -nk 3
ps aux --sort=%cpu | grep -v 'root' | head -n 35
Show processes
ps -ef
Show RAM and CPU
ps -eo cmd,%cpu,%mem
Show processes with ASCII art process tree
ps -ef --forest
Show pids of process
ps -ef | grep -v grep | grep <process_name> | awk '{ print $2 }'
Print the variables with which the process was started
ps ewww
- us, user : time running un-niced user processes
- sy, system : time running kernel processes
- ni, nice : time running niced user processes
- id, idle : time spent in the kernel idle handler
- wa, IO-wait : time waiting for I/O completion
- hi : time spent servicing hardware interrupts
- si : time spent servicing software interrupts
- st : time stolen from this vm by the hypervisor
PID – Process Id : This is a unique number used to identify the process.
User – The username of whoever launched the process.
PR – Priority : The priority of the process. Processes with higher priority will be favored by the kernel and given more CPU time than processes with lower priority. Oddly enough, the lower this value, the higher the actual priority; the highest priority on *nix is -20 and the lowest is 20.
NI – Nice value : nice is a way of setting your process’ priority. See here for more details.
VIRT – Virtual Memory Size (KiB) : The total amount of virtual memory used by the process.
RES – Resident Memory Size (KiB) : The non-swapped physical memory a task has used.
SHR – Shared Memory Size (KiB) : The amount of shared memory available to a task, not all of which is typically resident. It simply reflects memory that could be potentially shared with other processes.
S – Process Status : The status of the task which can be one of:
- ‘D’ = uninterruptible sleep
- ‘R’ = running
- ‘S’ = sleeping
- ‘T’ = traced or stopped
- ‘Z’ = zombie
%CPU – CPU Usage : The percentage of your CPU that is being used by the process. By default, top displays this as a percentage of a single CPU. On multi-core systems, you can have percentages that are greater than 100%. For example, if 3 cores are at 60% use, top will show a CPU use of 180%. See here for more information. You can toggle this behavior by hitting Shifti while top is running to show the overall percentage of available CPUs in use.
%MEM – Memory Usage (RES) : A task’s currently used share of available physical memory (RAM).
TIME+ – CPU Time, hundredths : Total CPU time the task has used since it started.
COMMAND – Command Name or Command Line : To see the full command line that launched the process, start top with the -c flag : top -c.
Batch mode and clouse
top -b -n 1
strace -f -tt -s <number of symbols> -o <log file> <application name>
pgrep <name of application> | awk '{print "-p " $1}' | xargs strace -f -tt -s <number of symbols> -o <log file>
gdb <program or dump>
Show allocated file descriptors, not use file descriptors, maximum of file descriptors
cat /proc/sys/fs/file-nr
Show proccess descriptors
ls -l /proc/<number of proccess>/fd
Truncate file
: > <path to file>
Truncate descriptor
: > proc/<pid>/fd/$fd
Show deleted files
lsof -nP | grep '(deleted)'
lsof -nP +L1