Throw stack trace from program kill

Era Scarecrow rtcvb32 at yahoo.com
Mon Jan 17 05:50:18 UTC 2022


On Sunday, 16 January 2022 at 18:03:53 UTC, Paul Backus wrote:
> On POSIX, you can use the `sigaction` function to install a 
> signal handler for `SIGINT`, the signal generated by CTRL+C. To 
> terminate the program with a stack trace, simply have the 
> signal handler `throw` an `Error`.

  I never quite got deep enough to start using these. Though i can 
tell a lot of programs take advantage of this in different ways. 
Example, optipng or jpegoptim will likely have a catch and if 
it's killed it would do cleanup then quit.

  **So**, normally said image optimizers create a new file as 
**somefile.jpg.tmp12345**, and if it is uninterrupted 
**somefile.jpg** is deleted and **somefile.jpg.tmp12345** is 
renamed to the original file; On the other hand interrupted 
execution would close the temp file and then delete it before 
returning control, leaving the original file untouched.


  As for how to handle things outside of cleanup, I'm not quite so 
sure. I don't see why you couldn't do a stacktrace or core dump a 
file with the current state you could then look at (*and maybe 
attach a debugger*).


More information about the Digitalmars-d-learn mailing list