<commit_before>/*
 * sig_demo.C
 *   Ignore ^C, catch and respond to ^| and USR1 signal.
 *
 * <NAME>, 2002
 */

#include <iostream>
#include <unistd.h>
#include <signal.h>

using namespace std;

//
// handle_signal
//   Called asynchronously when signals are received.
//   It's not generally safe to use cout in a signal handler.
//
//   int the_sig is the type of signal received.
//
void handle_signal(int the_sig)
{
  switch(the_sig) {
  case SIGQUIT:
    cout << "Caught SIGQUIT.\n";
    break;
  case SIGUSR1:
    cout << "Caught SIGUSR1.\n";
    break;
  }
}

main()
{
  int i;

  // set ^C to be ignored
  signal(SIGINT,SIG_IGN);

  // set handler to catch ^| and USR1 signal
  signal(SIGQUIT,handle_signal);
  signal(SIGUSR1,handle_signal);

  // count for a while
  for (i=0; ;i++) {
    cout << i << endl;
    sleep(1);
  }
}<commit_msg>check return value from sleep.<commit_after>/*
 * sig_demo.C
 *   Ignore ^C, catch and respond to ^| and USR1 signal.
 *
 * <NAME>, 2002-2015
 */

#include <iostream>
#include <unistd.h>
#include <signal.h>

using namespace std;

//
// handle_signal
//   Called asynchronously when signals are received.
//   It's not generally safe to use cout in a signal handler.
//
//   int the_sig is the type of signal received.
//
void handle_signal(int the_sig)
{
  switch(the_sig) {
  case SIGQUIT:
    cout << "Caught SIGQUIT.\n";
    break;
  case SIGUSR1:
    cout << "Caught SIGUSR1.\n";
    break;
  }
}

main()
{
  // set ^C to be ignored
  signal(SIGINT,SIG_IGN);

  // set handler to catch ^| and USR1 signal
  signal(SIGQUIT,handle_signal);
  signal(SIGUSR1,handle_signal);

  // count for a while
  int i, timeleft;
  for (i=0; ;i++) {
    cout << i << endl;
    timeleft = sleep(1);
    if (timeleft != 0)
      cout << "woke with " << timeleft << " second left" << endl;
  }
}
{'fraction_non_alphanumeric': 0.14160743575724438, 'fraction_numerical': 0.014762165117550574, 'mean_word_length': 2.78099173553719, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1821171', 'n_tokens_mistral': 697, 'n_tokens_neox': 671, 'n_words': 202}