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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:43:13+00:00 2026-05-13T16:43:13+00:00

Please check the following code #include <stdio.h> #include <string.h> #include <stdlib.h> #include <termios.h> #include

  • 0

Please check the following code

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/time.h>
#include <time.h>

#define CLOCKID CLOCK_REALTIME
#define SIG SIGRTMIN
int reset = 0;
void changemode(int);
int  kbhit(void);
int pfds[2];

static void handler(int sig, siginfo_t *si, void *uc)
{
    write(pfds[1], "reset", 6);
}

int main(void)
{
    int ch;
    timer_t timerid;
    struct sigaction sa;
    struct itimerspec its;
    struct sigevent sev;
    long long freq_nanosecs;
    char buf[30];

    pipe(pfds);

    sa.sa_flags = 0;
    sa.sa_sigaction = handler;
    sigemptyset(&sa.sa_mask);
    if (sigaction(SIG, &sa, NULL) == -1)
    {
        printf("Error\n");
        exit(1);
    }

    changemode(1);

    sev.sigev_notify = SIGEV_SIGNAL;
    sev.sigev_signo = SIG;
    sev.sigev_value.sival_ptr = &timerid;
    if (timer_create(CLOCKID, &sev, &timerid) == -1)
    {
        printf("Error timer_create");
        exit(1);
    }

    its.it_value.tv_sec = 1;
    its.it_value.tv_nsec = 0;
    its.it_interval.tv_sec = its.it_value.tv_sec;
    its.it_interval.tv_nsec = its.it_value.tv_nsec;

    if (timer_settime(timerid, 0, &its, NULL) == -1)
    {
        printf("Error timer_settime");
        exit(1);
    }

    while(1)
    {
        if (kbhit())
        {
            ch = getchar();
            printf("%d %c\n", ch, ch);
            if (ch == 'q')
            {
                printf("\nQuitting...\n");
                break;
            }
        }
        else
        {
            memset(buf, 0, 30);
            read(pfds[0], buf, 6);
            printf("\n%s", buf);
        }
    }

    changemode(0);
    return 0;
}

void changemode(int dir)
{
    static struct termios oldt, newt;

    if ( dir == 1 )
    {
        tcgetattr( STDIN_FILENO, &oldt);
        newt = oldt;
        newt.c_lflag &= ~( ICANON | ECHO );

        tcsetattr( STDIN_FILENO, TCSANOW, &newt);
    }
    else
        tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
}

int kbhit (void)
{
    fd_set rdfs;

    FD_ZERO(&rdfs);
    FD_SET (STDIN_FILENO, &rdfs);
    FD_SET (pfds[0], &rdfs);

    select(FD_SETSIZE, &rdfs, NULL, NULL, NULL);
    return FD_ISSET(STDIN_FILENO, &rdfs);

}

But whenever the signal SIGRTMIN is generated STDIN_FILENO is set (FD_ISSET) althought i’ve not entered anything in the terminal. How to make select ignore STDIN_FILENO when SIGRTMIN is generated by the timer?

  • 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-13T16:43:14+00:00Added an answer on May 13, 2026 at 4:43 pm

    If you are using Linux, you should use pselect instead of select.

    If not, you should check the error code returned by select. If it is EINTR, it is possible (but I am not sure) that you might have to call select again to check the status of the fds.

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

Sidebar

Ask A Question

Stats

  • Questions 340k
  • Answers 341k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're using OR (||) when you should be using AND… May 14, 2026 at 4:51 am
  • Editorial Team
    Editorial Team added an answer Temporary tables are only visible to the connection used to… May 14, 2026 at 4:51 am
  • Editorial Team
    Editorial Team added an answer From Using Nullable Types (C# Programming Guide) (Link updated circa… May 14, 2026 at 4:51 am

Related Questions

I've created a question about this a few days . My solution is something
I need to manipulate data in fixed array involving mid insertion. Rather than using
Edit: I've edited the sample to better resemble the problem I have, now the
I'm using the following code (via ' Dark Side of the Carton ') to
I have an existing web application that I am converting to use CakePHP. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.