Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!ames!amdahl!nsc!taux01!gil From: gil@taux01.UUCP (Gil Shwed) Newsgroups: comp.unix.wizards Subject: Re: Trapping SIGTSTP and then suspeding Message-ID: <2697@taux01.UUCP> Date: 10 Oct 89 06:45:26 GMT References: Reply-To: gil@taux01.nsc.com (Gil Shwed) Distribution: comp Organization: National Semiconductor (IC) Ltd, Israel Lines: 41 In article t45126@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