Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Maybe you should read up on limits, limits.conf. Setting these may help you out much better. – jippie Jun 14 '12 at 15:31
up vote 2 down vote accepted

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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