Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6636609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:12:27+00:00 2026-05-25T23:12:27+00:00

I am supposed override the Ctrl C signal and use it to print a

  • 0

I am supposed override the CtrlC signal and use it to print a message. It is not supposed to end the program.

What happens so far is that when CtrlC is pressed it prints the message, but ends the program.

When I asked my professor he told me to do this:
You need to make your signal handler keep from continuing to process the signal. Right now the signal is being handled by your code and then going on to the parent handler.

Is there a method I am supposed to add or do i need to move the signal installers someplace?

This is my code so far:

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>  
#include <sys/types.h>
#include <signal.h> 
#include "Input.h"
#include "CircleBuff.h"

//void handler_function(int signal_id);

void catch_int(int sig_num){

    //reset the signal handler again to catch_int, for next time
    signal(SIGINT, catch_int);
    //print message
    printf("Print History");
    fflush(stdout);
}

void printHistory(CircleBuff hist){
    cout << "Complete History:\n" << endl;
    hist.print();
    cout << endl;
}

int main(int argc, char** argv){

  struct sigaction signal_action;                /* define table */
  signal_action.sa_handler = catch_int;   /* insert handler function */
  signal_action.sa_flags = 0;                    /* init the flags field */
  sigemptyset( &signal_action.sa_mask );     /* are no masked interrupts */
  sigaction( SIGINT, &signal_action, NULL ); /* install the signal_action */

  do{


  //My code: where the value report will be assigned within.

  } while(report != 1)

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:12:28+00:00Added an answer on May 25, 2026 at 11:12 pm

    Whoa, way too much code to sift through. However, if you use the C standard library, you should get the desired behaviour. Here’s a C++ version:

    #include <iostream>
    #include <csignal>
    
    sig_atomic_t sigflag = 0;
    
    void sighandler(int s)
    {
      // std::cerr << "Caught signal " << s << ".\n"; // this is undefined behaviour
      sigflag = 1; // something like that
    }
    
    int main()
    {
      std::signal(SIGINT, sighandler);
    
      // ... your program here ...
    
      // example: baby's first loop (Ctrl-D to end)
      char c;
      while (std::cin >> c)
      {
        if (sigflag != 0) { std::cerr << "Signal!\n"; sigflag = 0; }
      }
    }
    

    This will catch Ctrl-C (which raises SIGINT), and the signal handler is not replaced, so it’ll fire every time, and nobody is terminating the program.

    Note that signal handlers are inherited by fork()ed children.

    The Posix function sigaction() allows you to register “one-shot” handlers which are replaced by the standard handler after they’re invoked once. That’s more advanced and Posix-specific, though.

    Edit: As @Dietrich points out, you should never do any real work inside a signal handler. Rather, you should set a flag (I provided an example), and check for that flag inside your loop (and print the message there). I’ll amend the example for that, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My understanding is that you're typically supposed to use xor with GetHashCode() to produce
I'm creating an Android application that is supposed to use SAX (javax.xml.parsers.SAXParser) to parse
Supposed that I have two arrays: Dim RoomName() As String = {(RoomA), (RoomB), (RoomC),
I'm supposed to write a wrapper function to MD5 hashing that restricts the input
I'm supposed to program in Python, and I've only used Python for 3 weeks.
How is one supposed to use ServletScopes.scopeRequest() ? How do I get a reference
Im using a fragment that is supposed to display a webview. When I try
I have an ImageView subclass that is supposed to display a logo in the
I have an abstract class that is supposed to become the base of a
I came across this puzzle in a programming contest where I am not supposed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.