Question

Write any C code to: - Overwrite a signal handler to use a provided function Please...

Write any C code to:

- Overwrite a signal handler to use a provided function

Please explain the steps

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

/* A C program that does not terminate when Ctrl+C is pressed */

#include <stdio.h>

#include <signal.h>

  

/* Signal Handler for SIGINT */

void sigintHandler(int sig_num)

{

    // Reset handler to catch SIGINT next time.

    signal(SIGINT, sigintHandler);

    printf("\n Cannot be terminated using Ctrl+C \n");

    fflush(stdout);

}

  

int main ()

{

    // Set the SIGINT (Ctrl-C) signal handler to sigintHandler

    signal(SIGINT, sigintHandler);

  

    /* Infinite loop */

    while(1)

    {        

    }

    return 0;

}

Output: When Ctrl+C was pressed two times

 
 Cannot be terminated using Ctrl+C
 
 Cannot be terminated using Ctrl+C

Note: Press Ctrl+Z to exit the process or else it will run in infinite loop.

Add a comment
Know the answer?
Add Answer to:
Write any C code to: - Overwrite a signal handler to use a provided function Please...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT