|
From: Jeroen N. W. <jn...@xs...> - 2005-08-27 10:25:35
|
On Friday 26 August 2005 21:29, Christian Parpart wrote:
> On Friday 26 August 2005 18:55, Jeroen N. Witmond wrote:
>> > On Friday 26 August 2005 09:50, Dennis Lubert wrote:
>> > I would like to be able to dump them into a file (just like the
>> coredump,
>> > but
>> > w/o crashing), and review them with a hex-editor (for example).
>>
>> #include <sys/types.h>
>> #include <unistd.h>
>> #include <signal.h>
>>
>> /* Brute force method of dumping core on the fly. */
>> void dump_core()
>> {
>> if (fork() == 0)
>> raise(SIGQUIT);
>> }
>>
>> /* Simple program to test it. */
>> #include <stdio.h>
>>
>> int main(int argc, char** argv)
>> {
>> printf("About to dump ...");
>> dump_core();
>> printf(" done.\n");
>> }
>>
>> Core dumps must be enabled. (`ulimit -c unlimited` under bash.) gdb
>> likes
>> the resulting core file just fine.
>
> Heya, I love that piece of code :-D
>
> However, one question may remain: why SIGQUIT and not SIGSEGV? I mean,
> what's
> SIGQUIT been used for usually?
>
SIGQUIT (CTRL-\) is a stronger version of SIGINT (CTRL-C). The default
action is to dump core and terminate, whereas the default action of SIGINT
is just to terminate. But for the fact that it mostly originates from the
keyboard, SIGQUIT is used here for what it is intended for. Any other core
dumping signal (e.g. SIGSEGV) could be used, but that opens the door to
confusion, as they suggest errors that aren't there. (See also `man 7
signals`.)
Jeroen.
|