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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:37:11+00:00 2026-05-20T08:37:11+00:00

struct sigaction psa; I have enabled my signal handler in the main function as

  • 0
  struct sigaction psa;

I have enabled my signal handler in the main function as shown below:

    memset (&psa, 0, sizeof (psa));
    psa.sa_handler = pSigHandler;
    sigaction (SIGALRM, &psa, NULL);
    sigaction(SIGVTALRM, &psa, NULL);
    sigaction(SIGPROF, &psa, NULL);

My signal handler is like this:

static void pSigHandler(int signo){
    printf("Pareint signum: %d", signo);// debug
    switch (signo) {
        case SIGALRM:
            printf("P SIGALRM handler");//debug
            break;
        case SIGVTALRM:
            printf("P SIGVTALRM handler");//debug
            break;
        case SIGPROF:
            printf("P SIGPROF handler");//debug
            break;
        default: /*Should never get this case*/
            break;
    }
    return;
}

Now my question may be obvious to some people, why didn’t I see the printed debug lines when I run this? In fact, nothing was printed. Thank you very much for helping me to understand this. I’m running it on Linux, used Eclipse to program.

  • 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-20T08:37:11+00:00Added an answer on May 20, 2026 at 8:37 am
    #include <stdio.h>
    #include <signal.h>
    
    static void pSigHandler(int signo){
        switch (signo) {
                case SIGTSTP:
                printf("TSTP");
                fflush(stdout);
                break;
        }
    }
    
    int main(void)
    {
        struct sigaction psa;
        psa.sa_handler = pSigHandler;
        sigaction(SIGTSTP, &psa, NULL);
        for(;;) {}
        return 0;
    }
    

    Because you need to fflush(stdout)

    try with C-z

    I’m not even sure if it’s safe to use stdio in a signal handler though.

    Update: http://bytes.com/topic/c/answers/440109-signal-handler-sigsegv

    According to that link, you should not do this.

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

Sidebar

Related Questions

I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
Say I have a struct s with an int pointer member variable i. I
I have a struct defined like follows as part of an object. I'm trying
I have a c# struct where I need to forbid calling the no args
I have a structure: struct pkt_ { double x; double y; double alfa; double
I want to write a signal handler to catch SIGSEGV. I protect a block
I am trying to create a handler for the exit signal in c and
I have written a program that handles signal for Floating point exception and I
I have a custom shell program in which I have included signal.h , unistd.h
struct aPoint { int somaVertical; int somaHorizontal; int valor; }; I have an array

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.