All,
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?

link|improve this question

71% accept rate
Just follow man page. – Prince John Wesley Oct 24 '11 at 6:44
feedback

1 Answer

#!/bin/bash
# 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 $$ 
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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