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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:58:12+00:00 2026-06-17T03:58:12+00:00

#include <stdio.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> void sigint_handler(int); int main() { signal(SIGINT,

  • 0
#include  <stdio.h>
#include  <signal.h>
#include <stdlib.h>
#include <unistd.h>

void sigint_handler(int);

int  main()
{
    signal(SIGINT, sigint_handler);

     while (1){
         pause();
     }
    printf("Out..\n");
    return 0;
}

 void sigint_handler(int sig)
{

    printf("killing process %d\n",getpid());
    exit(0);
}

I dont get: Out… after ctrl+c
So never returns on while or getting out. How can i fix it, to continiue in main, and print “Out…”?

  • 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-06-17T03:58:13+00:00Added an answer on June 17, 2026 at 3:58 am

    I dont get: Out… after ctrl+c

    Because the signal handler immediately ends the process so main never gets the chance of actually doing the printf. I suspect you don’t actually want to exit in the handler. You should take the pause out of the loop and wait until the signal gets delivered.

    This isn’t the best way of waiting for a signal. For starters it is conceivable that the user could send the SIGINT before you get the chance to pause. The signal would be lost and pause(2) would block until the end of time.

    You should probably use sigsuspend or the simpler sigpause.

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

Sidebar

Related Questions

#include<stdio.h> #include<signal.h> #include<stdlib.h> void handler(int signo) { printf(First statement); system(date); exit(EXIT_SUCCESS); } int main()
#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
Here's a simple C file: #include <stdio.h> #include <stdlib.h> int main() { printf(hi there!\n);
I have the following code: #include <stdio.h> #include <time.h> #include <stdlib.h> #include <unistd.h> int
Simple code: #include <signal.h> #include <stdio.h> #include <unistd.h> #include <iostream> using namespaces td; bool
#include<stdio.h> #include<math.h> int main(int argc, char **argv){ // read in the command-line argument double
My test application is #include <sys/types.h> #include <sys/wait.h> #include <signal.h> #include <unistd.h> #include <stdio.h>

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.