1848419 Members
2293 Online
104027 Solutions
New Discussion

Control+C in ksh

 
SOLVED
Go to solution
YLTan
Frequent Advisor

Control+C in ksh


is it possible to disable Ctrl+C keystrokes from sending a INT signal in ksh?

I have a scripts that use to startup tomcat java process. The process attached itself to root 1 and completed it startup process but when i do Ctrl+C keystrokes to exit to prompt the tomcat java process dies.
tyl
3 REPLIES 3
Mark Grant
Honored Contributor
Solution

Re: Control+C in ksh

just put this near the top of your script

trap "" 2
Never preceed any demonstration with anything more predictive than "watch this"
Graham Cameron_1
Honored Contributor

Re: Control+C in ksh

or reset the INT signal to some other key,
eg
stty intr ^Y


stty -a shows them all.

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Elmar P. Kolkman
Honored Contributor

Re: Control+C in ksh

I would go for a combination of both... Using stty to set it to a unknown key combination (try to use something a user won't accidentally type, for instance some character above ascii code 128:
stty intr \222

Remember that stty doesn't set your interrupt only for the duration of your script, but also for when the script is finished. So when you finish the script, set it back to ^C, or better, build the script like this, with your real commands at the #Do your stuff:
trap 2 "echo Please do not interrupt this program"
OLDSETTINGS=$(stty -g)
stty intr \222

# Do your stuff

stty $OLDSETTINGS
Every problem has at least one solution. Only some solutions are harder to find.