Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I trigger SIGINT in this program? #include #include #include #include void sig_handler(int); volatile sig_atomic_t cleanup_exit; int main() { // This variable determines if

How do I trigger SIGINT in this program?

#include #include #include #include

void sig_handler(int);

volatile sig_atomic_t cleanup_exit;

int main() { // This variable determines if we should exit our driver loop // Type sig_atomic_t is an integer that is guaranteed to be processed atomically // Atomically means operations cannot be interrupted (no race conditions) // Why atomic? Consider what happens if a signal is received in the handler cleanup_exit = false;

// Install our signal handlers signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); // Loop until SIGTERM

// Use pkill(1) to send the termination signal SIGTERM puts("Program running..."); while (! cleanup_exit) { ; }

puts("Cleaning up and exiting"); return 0; }

void sig_handler(int sig) { // save errno if you are doing anything that could trigger an error // i.e. anything that is not async-signal-safe int save_errno = errno;

switch (sig) { case SIGINT : puts("CTRL-C pressed"); break; case SIGTERM : puts("SIGTERM received"); cleanup_exit = true; break;

default : printf("%d not handled ", sig); }

errno = save_errno; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions

Question

Define humanised Big Data.

Answered: 1 week ago