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

I have a shell script where I want to call a function to do some cleanup if user presses the ctrl-z key(SIGTSTP signal). I read about the trap command and found an example where I can trap the ctrl-c key. Is there a way to intercept the SIGTSTP signal?

share|improve this question
Just follow man page. – Prince John Wesley Oct 24 '11 at 6:44
# ctrl + z handler 
function suspendHandle() {
 echo "$@"
# trap the SIGTSTP signal
# suspendHandle is a handler function with the parameters "trapping ctrl + z"
trap "suspendHandle trapping ctrl + z" 20 
# send SIGTSTP signal to current shell
kill -s 20 $$ 
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.