[comp.sys.sgi] exit signal

Dan Karron@UCBVAX.BERKELEY.EDU (12/16/90)

How can I set a signal handler for a software exit() call ? I am
looking to catch programs that exit via an exit(value) call, or fall
off the end of the main procedure. I do not have control of the user code.

I want to save the window state of the application program. I have
a macro to edit "exit(value)" to "Exit(value)", but that does not catch
mains falling off the end, or exit() with no args.

I tried SIGTERM, but that does not do what I want. What does it do ?

Cheers!

dan.
+-----------------------------------------------------------------------------+
| karron@nyu.edu (E-mail alias that will always find me)                      |
| Fax: 212 340 7190           *           Dan Karron, Research Associate      |
| . . . . . . . . . . . . . . *           New York University Medical Center  |
| 560 First Avenue           \*\    Pager <1> (212) 397 9330                  |
| New York, New York 10016    \**\        <2> 10896   <3> <your-number-here>  |
| (212) 340 5210               \***\_________________________________________ |
| Main machine: karron.med.nyu.edu (128.122.135.3) IRIS 85GT                  |
+-----------------------------------------------------------------------------+

jmb@patton.wpd.sgi.com (Jim Barton) (12/18/90)

In article <9012160645.AA10200@karron.med.nyu.edu>, Dan
Karron@UCBVAX.BERKELEY.EDU writes:
 
> How can I set a signal handler for a software exit() call ? I am
> looking to catch programs that exit via an exit(value) call, or fall
> off the end of the main procedure. I do not have control of the user code.

Your description is a little unclear of what you want - I don't know
what you mean by not having control of the user code. Guessing, the
easiest way to do this is to use dbx. Ask dbx to stop on a call to exit,
or even trap the exit system call. dbx will also catch any signals
posted to the program, so you can always catch the program when it is
going south.

> I want to save the window state of the application program. I have
> a macro to edit "exit(value)" to "Exit(value)", but that does not catch
> mains falling off the end, or exit() with no args.

I'm still a little confused about what you're looking for, but one thing
to try here might be a call to 'pause()'. This basically hangs the
program out into limbo until you kill it, so it should leave your window
up on the screen. Again, perhaps dbx is the best thing to use for this task.

By the way, you CAN use dbx to grab a running process and debug it - use
the -p option (and, as always, LATFM).

> 
> I tried SIGTERM, but that does not do what I want. What does it do ?
> 

The signal(2) man page can give you some help here. But playing with
signals won't help you debug your program - dbx is still the best bet.

-- Jim Barton
   Silicon Graphics Computer Systems
   jmb@sgi.com

merritt@milton.u.washington.edu (Ethan Merritt) (12/19/90)

In article <1990Dec18.153942.15916@odin.corp.sgi.com> jmb@patton.wpd.sgi.com (Jim Barton) writes:
>In article <9012160645.AA10200@karron.med.nyu.edu>, Dan
>Karron@UCBVAX.BERKELEY.EDU writes:
> 
>> How can I set a signal handler for a software exit() call ? I am
>> looking to catch programs that exit via an exit(value) call, or fall
>> off the end of the main procedure. I do not have control of the user code.
>
>Your description is a little unclear of what you want - I don't know
>what you mean by not having control of the user code. Guessing, the
>easiest way to do this is to use dbx. Ask dbx to stop on a call to exit,
>or even trap the exit system call. dbx will also catch any signals
>posted to the program, so you can always catch the program when it is
>going south.

	I'm not entirely sure what Karron wants in his original posting, but
this reminds me of something which caused me much grief when I started porting
code to IRIX.  Nowhere that I can find in the various libraries is an
equivalent to the ANSI C atexit() routine, which allows you to establish
a line of exit handlers which get to clean up before the program exits, no
matter where that exit is triggered from.  As Karron mentions, SIGTERM looks
like it might be of some help, but in fact it isn't (too many exit condidions
do not set SIGTERM).

	Any chance of getting atexit() in the next release?

					    Ethan A Merritt
-------------------------------------------------------------------------------
Dept of Biological Structure                H510 Health Sciences
University of Washington SM-20              (206)543-8865
Seattle, WA 98195                           merritt@u.washington.edu
-------------------------------------------------------------------------------

davea@quasar.wpd.sgi.com (David B.Anderson) (12/21/90)

In article <13238@milton.u.washington.edu> merritt@milton.u.washington.edu (Ethan Merritt) writes:
[ stuff deleted ]
>	Any chance of getting atexit() in the next release?

atexit(3) is in the ANSI C release and in the next IRIX release.

Regards,
[ David B. Anderson  Silicon Graphics  (415)335-1548  davea@sgi.com ]
[``What can go wrong?''                           --Calvin to Hobbes]

bowen@wanda.SGI.COM (Jerre Bowen) (12/21/90)

In article <13238@milton.u.washington.edu>,
merritt@milton.u.washington.edu (Ethan Merritt) writes:
> In article <1990Dec18.153942.15916@odin.corp.sgi.com>
jmb@patton.wpd.sgi.com (Jim Barton) writes:
> >In article <9012160645.AA10200@karron.med.nyu.edu>, Dan
> >Karron@UCBVAX.BERKELEY.EDU writes:
> > 
> >> How can I set a signal handler for a software exit() call ? I am
> >> looking to catch programs that exit via an exit(value) call, or fall
> >> off the end of the main procedure. I do not have control of the user code.
> >
> >Your description is a little unclear of what you want - I don't know
> >what you mean by not having control of the user code. Guessing, the
> >easiest way to do this is to use dbx. Ask dbx to stop on a call to exit,
> >or even trap the exit system call. dbx will also catch any signals
> >posted to the program, so you can always catch the program when it is
> >going south.
> 
> 	I'm not entirely sure what Karron wants in his original posting, but
> this reminds me of something which caused me much grief when I started
porting
> code to IRIX.  Nowhere that I can find in the various libraries is an
> equivalent to the ANSI C atexit() routine, which allows you to establish
> a line of exit handlers which get to clean up before the program exits, no
> matter where that exit is triggered from.  As Karron mentions, SIGTERM looks
> like it might be of some help, but in fact it isn't (too many exit condidions
> do not set SIGTERM).
> 
> 	Any chance of getting atexit() in the next release?
> 
> 					    Ethan A Merritt
>
-------------------------------------------------------------------------------
> Dept of Biological Structure                H510 Health Sciences
> University of Washington SM-20              (206)543-8865
> Seattle, WA 98195                           merritt@u.washington.edu
>
-------------------------------------------------------------------------------

	atexit() is available now as a separate product, released (I believe)
a month or so ago.  It is a routine in the ANSI libc; the package also includes
an ANSI-compliant compiler.  Check it out.

		Jerre Bowen (bowen@sgi.com)