cmkl_assignments/fall-2024/sys-arch/sys-102/00040/source/interrupt.c~

46 lines
688 B
C

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
int flag = 0;
// Handling signal function
void handle_signal(int signal)
{
// If signal is SIGINT
if (signal == SIGQUIT)
{
// Set flag to its complement
// Print the flag value
flag = !flag;
printf("Flag: %d\n", flag);
}
if (signal == SIGINT)
{
_exit(0);
}
}
int main()
{
clock_t t;
t = clock();
// Handling signal
signal(SIGQUIT, handle_signal);
signal(SIGINT, handle_signal);
// Let the program run until interrupt
while (1)
{
sleep(1);
}
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
printf("CPU Time: %f\n", t);
return 0;
}