mirror of
https://github.com/ioacademy-jikim/debugging
synced 2025-06-08 00:16:11 +00:00
34 lines
627 B
C
34 lines
627 B
C
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
fprintf(stderr, "starting ...\n");
|
|
|
|
// Three ways of going away...
|
|
if (argc > 1)
|
|
{
|
|
// Explicit exit() with exit code.
|
|
if (strcmp (argv[1], "exit") == 0)
|
|
{
|
|
fprintf(stderr, "exiting ...\n");
|
|
exit (1);
|
|
}
|
|
|
|
// Get killed by a signal.
|
|
if (strcmp (argv[1], "abort") == 0)
|
|
{
|
|
fprintf(stderr, "aborting ...\n");
|
|
kill(getpid(), SIGABRT);
|
|
}
|
|
}
|
|
|
|
// And finally, just return from main with success.
|
|
fprintf(stderr, "returning ...\n");
|
|
return 0;
|
|
}
|