My simple code will catch all the signals and show what signal you triggered at what exact time, but my problem is when the signal is caught the code will end and I couldn't trigger any other signal other SIGINT how can I trigger like (SIGSEGV , SIGABRT)
#include<stdio.h>
#include<time.h>
#include<signal.h>
#include<unistd.h>
//bos501_hw_signals_handling_Linux
void sig_handler(int signo)
{ time_t current_time;
char* c_time_string;
//Catch the current time. /
current_time = time(NULL);
// Convert to local time /
c_time_string = ctime(¤t_time);
//putting a condition for signals when they are caught to print the signal.
if (signo == SIGINT)
printf("received SIGUSR1\n"" ::Current time is %s", c_time_string);
else if (signo == SIGSEGV)
printf("received SIGSEGV\n"" ::Current time is %s", c_time_string);
else if (signo == SIGABRT)
printf("received SIGABRT\n"" ::Current time is %s", c_time_string);
else if (signo == SIGKILL)
printf("received SIGKILL\n"" ::Current time is %s", c_time_string);
else if (signo == SIGSTOP)
printf("received SIGSTOP\n"" ::Current time is %s", c_time_string);
}
int main(void)
{ //putting a conditon to show the signal that isnt caught like (SIGKILL,SIGSTOP)
if (signal(SIGUSR1, sig_handler) == SIG_ERR)
printf("\ncan't catch SIGUSR1\n");
if (signal(SIGSEGV, sig_handler) == SIG_ERR)
printf("\ncan't catch SIGSEGV\n");
if (signal(SIGABRT, sig_handler) == SIG_ERR)
printf("\ncan't catch SIGABRT\n");
if (signal(SIGKILL, sig_handler) == SIG_ERR)
printf("\ncan't catch SIGKILL\n");
if (signal(SIGSTOP, sig_handler) == SIG_ERR)
printf("\ncan't catch SIGSTOP\n");
// long wait to process the signal
while (1)
sleep(1);
return 0;
//end of code
}