Differences
This shows you the differences between two versions of the page.
linux_wiki:identify_cpu_memory_intensive_processes_adjust_process_priority_with_renice_and_kill_processes [2016/03/01 22:26] billdozor [Identify Cpu Memory Intensive Processes Adjust Process Priority With Renice And Kill Processes] |
linux_wiki:identify_cpu_memory_intensive_processes_adjust_process_priority_with_renice_and_kill_processes [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Identify Cpu Memory Intensive Processes Adjust Process Priority With Renice And Kill Processes ====== | ||
- | |||
- | **General Information** | ||
- | |||
- | Process wrangling. Get em cow-poke and watch out for zombies. | ||
- | |||
- | ---- | ||
- | |||
- | ==== Identify CPU/memory intensive processes ==== | ||
- | |||
- | === pgrep === | ||
- | |||
- | Grep for processes and return the PID. | ||
- | |||
- | Search processes for httpd | ||
- | <code bash> | ||
- | pgrep httpd -l | ||
- | </ | ||
- | * Returns PID (default) and name (-l) | ||
- | |||
- | Search for all processes being run by the user called " | ||
- | <code bash> | ||
- | pgrep -u user -l | ||
- | </ | ||
- | |||
- | All processes not owned by the root user | ||
- | <code bash> | ||
- | pgrep -v -u root -l | ||
- | </ | ||
- | |||
- | === ps === | ||
- | |||
- | All processes, user defined display options | ||
- | <code bash> | ||
- | ps -eo pid, | ||
- | </ | ||
- | * -e => every (all) processes | ||
- | * -o => user defined format | ||
- | |||
- | GNU Style Options | ||
- | <code bash> | ||
- | ps -elf | ||
- | </ | ||
- | * -e => every (all) processes | ||
- | * -l => long format | ||
- | * -f => full format listing (adds STIME column and displays CMDs full paths) | ||
- | |||
- | BSD Style Options | ||
- | <code bash> | ||
- | ps aux | ||
- | </ | ||
- | * a => eliminate the "only yourself" | ||
- | * u => display user oriented format | ||
- | * x => eliminate the "must have tty" restriction | ||
- | |||
- | === system load === | ||
- | |||
- | Load average | ||
- | * percentage of processing power used | ||
- | * Number of CPUs is important | ||
- | |||
- | Get the number of CPUs | ||
- | <code bash> | ||
- | grep -c proc / | ||
- | </ | ||
- | * -c => count of matched lines | ||
- | * proc => the string searched for in / | ||
- | |||
- | View load averages | ||
- | <code bash> | ||
- | w | ||
- | |||
- | OR | ||
- | |||
- | uptime | ||
- | | ||
- | </ | ||
- | * shows the: last minute, last 5 mins, last 15 mins load | ||
- | * last min = 0%, last 5 mins = 1%, last 15 mins = 4% | ||
- | * If 2 cpus, a load average of 1.00 would be 50% CPU load. (1.00 / 2 = .50) | ||
- | * If 2 cpus, a load average of 2.00 would be 100% CPU load. (2.00 / 2 = 1.00) | ||
- | |||
- | Percentage of total processing power in use = load average / (# of cpus) | ||
- | |||
- | === top === | ||
- | |||
- | Open top | ||
- | <code bash> | ||
- | top | ||
- | </ | ||
- | * Sorted by %cpu used by default | ||
- | |||
- | Interactive commands | ||
- | * z => toggle colors (easier to see highlighted columns) | ||
- | * x => highlight current sort column | ||
- | * 1 => expand CPU list to see individual usage | ||
- | * M => sort by %memory used | ||
- | * P => sort by %cpu used | ||
- | * < or > => change sort column | ||
- | * r => (renice) enter pid to renice, then nice level (selects top PID by default, can change) | ||
- | * k => (kill) enter pid, then signal to send (selects top PID by default, can change) | ||
- | |||
- | Start top with a screen update delay of 2 seconds | ||
- | <code bash> | ||
- | top -d 2 | ||
- | </ | ||
- | * Default is update the display every 3 seconds | ||
- | |||
- | ---- | ||
- | |||
- | ==== adjust process priority with renice ==== | ||
- | |||
- | Highest priority => -20 (the least nice to other processes)\\ | ||
- | Lowest priority => 19 (the most nice to other processes)\\ | ||
- | Default nice level if nice run, but level not specified => 10 | ||
- | |||
- | Start program with a nice level of 5 | ||
- | <code bash> | ||
- | nice -n 5 httpd | ||
- | </ | ||
- | |||
- | Change nice level of a running process to -5 | ||
- | <code bash> | ||
- | renice -n -5 2879 | ||
- | </ | ||
- | |||
- | Change nice level of all running httpd processes to -10 | ||
- | <code bash> | ||
- | renice -n -10 $(pgrep httpd) | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ==== kill processes ==== | ||
- | |||
- | List kill signals | ||
- | <code bash> | ||
- | kill -l | ||
- | </ | ||
- | |||
- | * 1 (SIGHUP) => hang up, similar to closing a terminal window | ||
- | * 2 (SIGINT) => keyboard interrupt (ctrl+c) | ||
- | * 3 (SIGQUIT) => ask process to quit | ||
- | * 9 (SIGKILL) => Kill process immediately, | ||
- | * 15 (SIGTERM) => Asks process to terminate cleanly. Default when nothing passed. | ||
- | * 18 (SIGCONT) => continue process that was stopped | ||
- | * 19 (SIGSTOP) => stop the process, not ignorable | ||
- | * 20 (SIGTSTP) => stop that can be ignored | ||
- | |||
- | Kill process by name (instead of PID) | ||
- | <code bash> | ||
- | pkill httpd | ||
- | </ | ||
- | * Kills all process ids named httpd, sending signal 15 (SIGTERM) | ||
- | |||
- | Remove a user's ssh session (kick user off system) | ||
- | <code bash> | ||
- | pkill -u rjones sshd | ||
- | </ | ||
- | |||
- | Kill all processes started from a specific terminal | ||
- | <code bash> | ||
- | pkill -t pts/1 | ||
- | </ | ||
- | * This does NOT kick them off the system, only kills their running programs started from that session. | ||
- | |||
- | Stop a process that is job #1 | ||
- | <code bash> | ||
- | kill -SIGSTOP %1 | ||
- | </ | ||
- | * Alt command: kill -19 %1 | ||
- | |||
- | Contine the process that is job #1 | ||
- | <code bash> | ||
- | kill -SIGCONT %1 | ||
- | </ | ||
- | * Alt command: kill -18 %1 | ||
- | |||
- | Kill an individual process with PID 2594 | ||
- | <code bash> | ||
- | kill -SIGKILL 2594 | ||
- | </ | ||
- | * Alt command: kill -9 2594 | ||
- | |||
- | ---- | ||