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

  • Home
  • SEARCH
  • 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 8904487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:08:43+00:00 2026-06-15T02:08:43+00:00

In the following program, pause is interrupted once, but then pause never returns. I

  • 0

In the following program, pause is interrupted once, but then pause never returns. I have set alarm to interrupt pause, so i am confused why pause never returns?

#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

static void sig_alrm(int);
static jmp_buf env_alrm;


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

    int x;
    x = setjmp(env_alrm);
    printf("setjmp was created with return value: %d\n", x);

    if(signal(SIGALRM, sig_alrm) == SIG_ERR)
    {
            printf("Error settting SIGALRM\n");
            exit(1);
    }


    if((x!= 0) && (x!=1))
    {

            printf("Error setting setjmp\n");
            exit(1);
    }

    printf("Line next to setjmp\n");
    x = alarm(2);
    printf("Alarm set for 2 seconds, remaning secs from previous alarm: %d\n");
    pause();
    printf("Line next to pause()\n");
    alarm(0);
    return 0;
}

static void sig_alrm(int signo)
{
    longjmp(env_alrm, 1);
}

Here is the output and the last line shows where the application pauses

setjmp was created with return value: 0
Line next to setjmp
Alarm set for 2 seconds, remaining secs from previous alarm: 0
setjmp was created with return value: 1
Line next to setjmp
Alarm set for 2 seconds, remaining secs from previous alarm: 0
  • 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-15T02:08:44+00:00Added an answer on June 15, 2026 at 2:08 am

    use sigsetjmp() and siglongjmp() instead, to save and restore the signal masks, which are not saved by default in Linux, to clear any pending signals, from man setjmp():

    POSIX does not specify whether setjmp() will save the signal mask. In System V it will not.By default, Linux/glibc follows the System V behavior. If you want to portably save and restore signal masks, use sigsetjmp()
    and siglongjmp()
    .

    Note: I’m not sure what you’re trying to accomplish, but your code looks like it’s supposed to run in an infinite loop, calling longjmp() restores execution as if it had just returned from setjmp() and it goes on forever.

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

Sidebar

Related Questions

What would cause my program to pause on Xcode? I have no breakpoints set
I have the following program made in Dev C++: #include <stdio.h> #include <stdlib.h> #include<string.h>
I have the following bat script: @echo off set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_32 set JRE_HOME=C:\Program Files\Java\jdk1.6.0_32\jre
Consider the following C program, 'pause.c': void main() { pause(); } Compiling this on
In following program . I have one doubt. I have declared one global variable
The following program doesn't build in VS11 beta, gcc 4.5, or clang 3.1 #include
I have the following program that generates a multiplication table. A formatting problem arises
I have a c program #include <stdio.h> int main () { printf(Hello); } On
See the following program: #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> main(void){ printf(Array
I'm doing this little program in C++ but in codeblocks appears the following error:

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.