home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / shell / 5130 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  1.2 KB

  1. Path: sparky!uunet!noc.near.net!hri.com!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!oakhill!stevet
  2. From: stevet@oakhill.sps.mot.com (Steve Turner)
  3. Newsgroups: comp.unix.shell
  4. Subject: signal traps in Bourne -- HELP!
  5. Message-ID: <1992Dec21.223804.5764@oakhill.sps.mot.com>
  6. Date: 21 Dec 92 22:38:04 GMT
  7. Organization: Motorola Inc., Austin, Texas
  8. Lines: 45
  9.  
  10. Is there a good way to tell a signal service routine to know which signal
  11. invoked it?  The script below shows how I'm approaching this, but
  12. surely there is a more elegant way... any suggestions?  Please
  13. send email to me directly. I'll post a summary if there is interest. 
  14.  
  15. ----------------- script follows -------------
  16.  
  17. #!/bin/sh
  18.  
  19. sigtrap()
  20. {
  21.     case $SIGNAL in
  22.         1) echo killed by SIGHUP ;;
  23.         2) echo killed by SIGINT ;;
  24.         # etc
  25.     esac
  26. }
  27.  
  28. sigcatch1() 
  29.     SIGNAL=1; sigtrap; exit $SIGNAL 
  30. }
  31. sigcatch2() 
  32.     SIGNAL=2; sigtrap; exit $SIGNAL 
  33. }
  34.  
  35. # etc for 32 signals
  36.  
  37. trap sigcatch1 1
  38. trap sigcatch2 2
  39.  
  40. # etc for 32 signals
  41.  
  42. # then run the main program below...
  43. read WORD
  44.  
  45. ----------------- end script -----------
  46.  
  47. Happy Holidays,
  48. -- 
  49.  Steve Turner                     Motorola, Inc.
  50.  stevet@risc.sps.mot.com          RISC Design Automation
  51.  512.891.8728                     Austin, TX 
  52.  
  53.