5

I find that sometimes my Linux will stop responding, so I need to switch to another terminal with CtrlAltF2, and type a command to kill the top CPU usage process or top IO usage process, so that the system can be responsive again.

This command should be short and execute quickly. I know the command kill, but I do not know how to get the top-est process PID or name.

I will add this command into shell alias or function.

  • 3
    Maybe you should read up on limits, limits.conf. Setting these may help you out much better. – jippie Jun 14 '12 at 15:31
4

running top with batch mode via -b should get you the information you're looking for.

Here's a very messy start to what you could do:

top -b -n 1 | head | grep -A 1 PID | grep "^[0-9]" | cut -f1 -d" " | xargs kill

You can always kill a process from an interactive run of top using the k key as well, since you might not like what it picks...

Not sure what kernel you're running, but cgroups may also be of use to you in addition to limits.conf

1

Keep top or htop running in a terminal somewhere. In top, press k then enter a PID to kill a process. In htop, move the cursor over the process you want to kill then press k.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.