takao@ihu1h.UUCP (John Takao Collier) (09/13/85)
Is there a way to get a trap to survive the exec of the shell? What I want to do is set a trap, exec a shell, continue on with an interactive session in the exec'ed shell, and have the trap turned on in the exec'ed shell. This comes in handy if you want to set a trap in a .profile, but want to exec a new shell in the .profile. For example, if the following commands are invoked: trap 'echo bye' 0 exec /bin/sh the trap disappears. I have tried various parameters to the shell, such as "-c" and "-i", but these experiments have failed, e.g.: exec /bin/sh -c 'trap "echo bye" 0' will exec the shell, read the string specified by the the "-c" parameter, reads the trap, then exits the exec'ed shell. I do not want to exit the shell. If you have a solution, be it elegant or ugly, I would very much like to see it. Thanks. -- --- John Takao Collier ..ihnp4!ihu1h!takao 1-312-979-3278 AT&T Bell Laboratories, Naperville-Wheaton Road, Naperville, IL 60566
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (09/17/85)
> Is there a way to get a trap to survive the exec of the shell? > What I want to do is set a trap, exec a shell, continue on with > an interactive session in the exec'ed shell, and have the trap > turned on in the exec'ed shell. Nope, any signal handler other than SIG_DFL or SIG_IGN is reset to SIG_DFL by an exec. You'll have to set up the signal handler inside the exec'ed shell.
curt@sdcrdcf.UUCP (Curt Dodds) (09/28/85)
In article <668@ihu1h.UUCP> takao@ihu1h.UUCP (John Takao Collier) writes: >Is there a way to get a trap to survive the exec of the shell? >What I want to do is set a trap, exec a shell, continue on with >an interactive session in the exec'ed shell, and have the trap >turned on in the exec'ed shell. > >This comes in handy if you want to set a trap in a .profile, but >want to exec a new shell in the .profile. > >For example, if the following commands are invoked: > >trap 'echo bye' 0 >exec /bin/sh > >the trap disappears. > >I have tried various parameters to the shell, such as "-c" and "-i", >but these experiments have failed, e.g.: > >exec /bin/sh -c 'trap "echo bye" 0' > >will exec the shell, read the string specified by the the "-c" parameter, >reads the trap, then exits the exec'ed shell. I do not want to exit >the shell. > >If you have a solution, be it elegant or ugly, I would very much like to >see it. > >Thanks. >-- > >--- >John Takao Collier ..ihnp4!ihu1h!takao 1-312-979-3278 >AT&T Bell Laboratories, Naperville-Wheaton Road, Naperville, IL 60566 Any time you do an exec you lose whatever you've done up to that point (except the environment I suppose). Sounds like what you want is the following: -------------------------------------------------- trap 'echo bye;sleep 2;trap 0;exit' 0 1 2 3 15 /bin/sh exit -------------------------------------------------- If signals 1,2,3 or 15 occur while /bin/sh is running or if /bin/sh exits the sequence of instructions within single quotes will be executed. -- Curt Dodds sdcrdcf!irdmega!curt