Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

If I run a for loop on the command line in sh, and I press control-C, it usually cancels the current running process, so I need to hold ^C until the shell itself catches it and breaks the loop. Is there a way to break current process and the loop immediately?

share|improve this question

Easiest way I know would be to suspend the foreground job (^z), then kill it using the job id (kill %JOB_ID)


[me@host]$ while [ : ]; do less /etc/motd; done # Ctrl-C can't kill this

After a Ctrl-z

[1]+  Stopped                 less /etc/motd

[me@host]$ kill %1

The number within the brackets ( [1] ) at the beginning of the suspension message gives you the job id.

You can also list out ids of suspended jobs using the the "jobs" command.

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.