Running a timeout function in the background

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a function:



int waiting()

fd_set input_set;
struct timeval timeout;
int ready_for_reading = 0;
int read_bytes = 0;

FD_ZERO(&input_set );
FD_SET(0, &input_set);

timeout.tv_sec = WAIT; // WAIT seconds
timeout.tv_usec = 0; // 0 milliseconds

printf("^[[10;53H^[[1;34;44m LOGIN TO BBS ^[[0;37m", WAIT);
printf("^[[11;53H^[[34;46m apply to bbs ^[[0;37m", WAIT);
printf("^[[12;53H^[[34;46m page sysop ^[[0;37m", WAIT);
printf("^[[13;53H^[[34;46m logout of bbs ^[[0;37m", WAIT);
printf("n", WAIT);

ready_for_reading = select(1, &input_set, NULL, NULL, &timeout);

if (ready_for_reading == -1)
return -1;

if (ready_for_reading)

else
exit(1);


return 0;



It times out, like it should, The problem is that it only works when the user doesn't input anything. I'd like it to work regardless of if the user inputs anything. Also, I'd like to run this function in the background. Is that possible?










share|improve this question

























    up vote
    0
    down vote

    favorite












    I have a function:



    int waiting()

    fd_set input_set;
    struct timeval timeout;
    int ready_for_reading = 0;
    int read_bytes = 0;

    FD_ZERO(&input_set );
    FD_SET(0, &input_set);

    timeout.tv_sec = WAIT; // WAIT seconds
    timeout.tv_usec = 0; // 0 milliseconds

    printf("^[[10;53H^[[1;34;44m LOGIN TO BBS ^[[0;37m", WAIT);
    printf("^[[11;53H^[[34;46m apply to bbs ^[[0;37m", WAIT);
    printf("^[[12;53H^[[34;46m page sysop ^[[0;37m", WAIT);
    printf("^[[13;53H^[[34;46m logout of bbs ^[[0;37m", WAIT);
    printf("n", WAIT);

    ready_for_reading = select(1, &input_set, NULL, NULL, &timeout);

    if (ready_for_reading == -1)
    return -1;

    if (ready_for_reading)

    else
    exit(1);


    return 0;



    It times out, like it should, The problem is that it only works when the user doesn't input anything. I'd like it to work regardless of if the user inputs anything. Also, I'd like to run this function in the background. Is that possible?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a function:



      int waiting()

      fd_set input_set;
      struct timeval timeout;
      int ready_for_reading = 0;
      int read_bytes = 0;

      FD_ZERO(&input_set );
      FD_SET(0, &input_set);

      timeout.tv_sec = WAIT; // WAIT seconds
      timeout.tv_usec = 0; // 0 milliseconds

      printf("^[[10;53H^[[1;34;44m LOGIN TO BBS ^[[0;37m", WAIT);
      printf("^[[11;53H^[[34;46m apply to bbs ^[[0;37m", WAIT);
      printf("^[[12;53H^[[34;46m page sysop ^[[0;37m", WAIT);
      printf("^[[13;53H^[[34;46m logout of bbs ^[[0;37m", WAIT);
      printf("n", WAIT);

      ready_for_reading = select(1, &input_set, NULL, NULL, &timeout);

      if (ready_for_reading == -1)
      return -1;

      if (ready_for_reading)

      else
      exit(1);


      return 0;



      It times out, like it should, The problem is that it only works when the user doesn't input anything. I'd like it to work regardless of if the user inputs anything. Also, I'd like to run this function in the background. Is that possible?










      share|improve this question













      I have a function:



      int waiting()

      fd_set input_set;
      struct timeval timeout;
      int ready_for_reading = 0;
      int read_bytes = 0;

      FD_ZERO(&input_set );
      FD_SET(0, &input_set);

      timeout.tv_sec = WAIT; // WAIT seconds
      timeout.tv_usec = 0; // 0 milliseconds

      printf("^[[10;53H^[[1;34;44m LOGIN TO BBS ^[[0;37m", WAIT);
      printf("^[[11;53H^[[34;46m apply to bbs ^[[0;37m", WAIT);
      printf("^[[12;53H^[[34;46m page sysop ^[[0;37m", WAIT);
      printf("^[[13;53H^[[34;46m logout of bbs ^[[0;37m", WAIT);
      printf("n", WAIT);

      ready_for_reading = select(1, &input_set, NULL, NULL, &timeout);

      if (ready_for_reading == -1)
      return -1;

      if (ready_for_reading)

      else
      exit(1);


      return 0;



      It times out, like it should, The problem is that it only works when the user doesn't input anything. I'd like it to work regardless of if the user inputs anything. Also, I'd like to run this function in the background. Is that possible?







      c timeout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 42 mins ago









      ignatius

      12339




      12339

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475118%2frunning-a-timeout-function-in-the-background%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475118%2frunning-a-timeout-function-in-the-background%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)