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 1044765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:52:47+00:00 2026-05-16T15:52:47+00:00

I am trying to make my program ignore Ctrl + C in unix which

  • 0

I am trying to make my program ignore Ctrl+C in unix which seems to work, the issue is that it keep writing “Syntax error”. Here is the code

extern "C" void ignore( int sig )
{            
    fprintf( stderr, "\n"); // Print a new line
    // This function does nothing except ignore ctrl-c
}

int main()
{           
    // For ctrl-c
    sigset( SIGINT, ignore );

    while (1) {
        getUserInput();
    }      

    return 0;
}

Everytime I hit Ctrl+C it runs through getUserInput again, which is the expected behavior, but it writes “Syntax error” as well. I checked and the “ignore” function gets executed, and once it has been executed, then it prints the error message, I am not sure why.

Does anyone have any clues please?

Thank you very much,

Jary

  • 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-16T15:52:48+00:00Added an answer on May 16, 2026 at 3:52 pm

    Do not use sigset(). Although it is in POSIX 2008, it is marked obsolescent – and also unsafe in threaded programs.

    You then have a choice between signal(), which is blessed by ISO C but has some undesirable characteristics, and sigaction() which is the preferred solution in POSIX systems.

    One key point with signal handling is to ensure you do not trap any signals that are ignored when you enter the program – unless you know something that the caller can’t (such as you need to trap SIGCHLD signals for dead children).

    This leads to the standard formulations, preached since time immemorial, for signal():

    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
        signal(SIGINT, ignore);
    

    Or, for sigaction():

    struct sigaction new_sa;
    struct sigaction old_sa;
    sigfillset(&new_sa.sa_mask);
    new_sa.sa_handler = SIG_IGN;
    new_sa.sa_flags = 0;
    
    if (sigaction(SIGINT, &new_sa, &old_sa) == 0 && old_sa.sa_handler != SIG_IGN)
    {
        new_sa.sa_handler = ignore;
        sigaction(SIGINT, &new_sa, 0);
    }
    

    Since you do not show us the getUserInput() function, there is no way we can prognosticate on why you see ‘Syntax Error’. However, if you have a grammar at work, it may well be that your read is not returning valid data, and the parser is unhappy with what is left in the buffer for it to process.

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

Sidebar

Related Questions

I'm trying to make a program that creates and reads a binary file, which
Im trying to make a program that retrieves an endless amount of numbers that
I'm trying to make a program that, using pointers, detects lines in an image
I'm trying to make a program that lets you input any one-step equation, and
I'm trying to make a program which will create a sum of directories the
I'm trying to make a program that can be hosted by many peoples, like
I am trying to make a program that can take an .mp3 file from
I am trying to make a program that automatically corrects the perspective of a
I am trying to make a program to work on top of an existing
I'm trying to make a program that reads the value at a certain address.

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.