Trapping SIGTSTP and then suspeding
Gil Shwed
gil at taux01.UUCP
Tue Oct 10 16:45:26 AEST 1989
In article <T45126.89Oct6084404 at iemisi.dhc> t45126 at iemisi.dhc (John Durko) writes:
>Can someone help me with a problem. I am trying to trap signal 18 (SIGTSTP)
>so that i can reset some terminal stuff before program is suspend by ^Z.
The following code should be used on 4.3BSD (SunOS included)
[ 4.2BSD derived systems should replace sigmask(i) with 1<<(i-1) ]:
in your main program:
signal(SIGTSTP, tstp);
Handler code:
tstp() {
/* Restore tty values, or whatever you like. */
/* First, Use the default action - STOP process */
signal(SIGTSTP, SIG_DFL);
/*
* Turn off blocking of SIGTSTP from blocked signals. Otherwise
* It will be masked until we get out of the handler.
*/
sigsetmask(sigblock(0) & ~sigmask(SIGTSTP));
/*
* Stop myself
*/
kill(getpid(), SIGTSTP);
/*
* Set handler again for next use.
*/
signal(SIGTSTP, tstp);
/* Restore/Set tty values back to programs' */
}
Hope that helps.
-- Gil
More information about the Comp.unix.wizards
mailing list