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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:14:31+00:00 2026-05-28T01:14:31+00:00

I want to repeatedly set up a SIGALRM and wait until it goes off,

  • 0

I want to repeatedly set up a SIGALRM and wait until it goes off, then do it again. In my handler function I have:

void handler(int signum)
{
    struct itimerval timer;
    struct sigaction sa; 

    sa.sa_handler = handler;

    timer.it_interval.tv_sec = 0;
    timer.it_interval.tv_usec = 0;
    timer.it_value.tv_usec = 0;
    timer.it_value.tv_sec = 1000;

    sigaction(SIGALRM, &sa, 0);
    setitimer(ITIMER_REAL, &timer, 0);

    printf("pause for me\n");
    pause();
}

and in my main I have:

int main(void)
{
    handler(0);
    return 0;
}

However, all it does is repeat twice then stalls. I want it to continue repeating. What’s the problem?

  • 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-28T01:14:31+00:00Added an answer on May 28, 2026 at 1:14 am

    struct sigaction has several fields which you are not initializing. The stack garbage you happen to get the first few times works and then you hit a case where it does not and your handler is not installed. You should test the sigaction() return. When you get -1 print a message including errno.

    You should call sigaction() once (from main() or similar). It will “stick” if you don’t set the SA_RESETHAND flag. Then your other existing code will probably work.

    For more accurate repeating timing you should take advantage of struct itimerval‘s it_interval which lets you set the next timer value so it will commence immediately when the current one fires.

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

Sidebar

Related Questions

I want to play one music repeatedly until user presses the toggle button off..
I have a python program/file that I want to run repeatedly and calculate the
I have stored set of MP3 files in my sd card. Now I want
I have implemented a custom IPrincipal that I set in protected void Application_PostAuthenticateRequest(Object sender,
I have a set of functions I want to be available to my web
I want to repeatedly execute a function in Python every 60 seconds forever (just
I want to repeatedly check a variable every time php wakes up from sleep().
I want to repeatedly zero a large 2d array in C. This is what
In my android app, I'm setting an alarm that I want to occur repeatedly,
For a linearLayout, I want to have a gradient along with a tiled (repeated)

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.