Using CheatSheets To Apply Best Practices

CheatSheet: Linux Process

CheatSheet: Linux Process


linkedin
github
slack

PRs Welcome

File me Issues or star this repo.

1.1 Find process

Name Comment
Sort processes by ram usage ps -eo size,pid,user,pcpu,command --sort -rss
Sort processes by cpu usage ps -eo size,pid,user,pcpu,command --sort -pcpu
Get parent process id by pid ps -o ppid= -p <pid>
Find process by name pgrep <process_name>
List zombie processes See zombie-process.sh
List all process ps aux, ps axjf

1.2 Top Command

Name Comment
Top show process full command line Use c to toggle
Top sort process by memory usage Shift+m
Top for certain processes top -p `pgrep -d "," java`

1.3 Examine process

Name Comment
Trace system calls and signals by pid strace -p <pid>
List all file handlers by pid lsof -p <pid>
Display process tree by pid pstree -A -n -p <pid>
List all listening ports by pid See proc-listen-ports.sh
Get process ram usage by pid sudo pmap -x <pid>

1.4 Kill process

Name Comment
Kill process gracefully kill <pid>, kill -15 <pid>, kill -TERM <pid>
Kill process by force kill -9 <pid>, kill -KILL <pid>
kill process by its full process name pkill <processname>
kill process by it’s partial name pkill -f <process-string>
Kill process by process name killall <process_name>

1.5 Explore /proc filesystem

Name Comment
Check process start command cat /proc/$pid/cmdline
Check process environment variables cat /proc/$pid/environ
Check process ulimits setting cat /proc/$pid/limits
Check cpu utilization /proc/loadavg
List all partitions /proc/partitions
List all modules /proc/modules
List TCP/UDP packages sudo cat /proc/$PID/net/nf_conntrack
Get current IP from /proc See proc-get-ip.sh

1.6 Linux Process Status

Status Type
Ready or running TASK_RUNNING(R)
Blocked (waiting for an event) TASK_INTERRUPTIBLE(S)
Blocked (usually for I/O) TASK_UNINTERRUPTIBLE(D)
Terminated but not cleaned up by its parent TASK_ZOMBIE(Z)
Execution stopped TASK_STOPPED(T)

1.7 More Resources

License: Code is licendiff under MIT License.




Leave a Reply

Your email address will not be published. Required fields are marked *