Using CheatSheets To Apply Best Practices

CheatSheet: Linux Process

CheatSheet: Linux Process

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
  pgrep <process_name>

1.2 Debug process

Name Comment
  strace -p <pid>
  lsof -p <pid>
  pstree -A -n -p <pid>

1.3 Kill process

Name Comment
Kill process gracefully kill <pid>, kill -15 <pid>, kill -TERM <pid>
Kill process forcefully 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.4 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
Get current IP from /proc See proc-get-ip.sh
Get process command line from /proc  
Get listening port for a given process  

1.5 More Resources

License: Code is licendiff under MIT License.




Leave a Reply

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