/
zatar
/
LinuxApi
Обзор
Документация
Войти
/
zatar
/
LinuxApi
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
21/21.1.c
53 строки
1 KB
Kirill Arshanitsa
Add chp 21 + fix 20.4
03 апр 2024, 21:49
03 апр 2024, 21:49
47320a5
Код
Авторство
О чём код?
#define _GNU_SOURCE #include <stdio.h> #include <signal.h> #include <string.h> #include <errno.h> #include <stdlib.h> void my_abort(void){ static int count; struct sigaction act; printf("Get SIGABRT count %d\n", count); count++; if (count > 1){ if(sigaction(SIGABRT, NULL, &act) ==-1){ printf("Error get sigaction SIGABRT %s\n", strerror(errno)); exit(EXIT_FAILURE); } act.sa_handler = SIG_DFL; if(sigaction(SIGABRT, &act, NULL) ==-1){ printf("Error set sigaction SIGABRT %s\n", strerror(errno)); exit(EXIT_FAILURE); } puts("SIGABRT set SIG_DFL"); } if(raise(SIGABRT)!=0){ printf("Error send SIGABRT %s\n", strerror(errno)); } } void sigHandlerAbrt(int sig){ printf("Get signal %d\n", sig); my_abort(); } int main(){ struct sigaction act; act.sa_handler = &sigHandlerAbrt; if(sigaction(SIGABRT, &act, NULL) ==-1){ printf("Error sigaction SIGABRT %s\n", strerror(errno)); exit(EXIT_FAILURE); } printf("Pid = %d, wait SIGABRT\n", getpid()); pause(); puts("Second pause"); pause(); exit(EXIT_SUCCESS); }