#include #include #include static void signal_handler (int signo); static timer_t timer_id = -1; #define ERROR (-1) int i = 0; void signal_handler(int signo) { // Perform a use-less task i++; } void init_signals (void) { struct sigaction sig_act; struct sigevent evp; struct itimerspec ttime; /* initialize sig_act */ sig_act.sa_handler = (void*)signal_handler; sig_act.sa_flags = 0; sigemptyset(&sig_act.sa_mask); sigaction(SIGUSR1, &sig_act, 0); evp.sigev_value.sival_int = 0; evp.sigev_signo = SIGUSR1; timer_create (CLOCK_REALTIME, &evp, &timer_id); ttime.it_value.tv_sec = 0; /* 0 S */ ttime.it_value.tv_nsec = 20000000; /* 20mS */ ttime.it_interval.tv_sec = 0; /* 0 S */ ttime.it_interval.tv_nsec = 20000000; /* 20mS */ /* fire off the periodic timer - relative mode = 0 */ timer_settime(timer_id, 0, &ttime, NULL); } static int get_input(char *buffer, int size) { char c; int status, counter, dummy; counter= 0; c = 0; status = 0; while (c != '\r') { dummy = getc(stdin); c = (char)dummy; if ((dummy != EOF) && (dummy != 0)) { if ( isprint(c) && (counter < size-1) ) { buffer[counter++] = c; } else if ((c == '\r') || (c == '\n')) { /* return user's str length - while loop will terminate */ status = counter; c = '\r'; } else { ; /* Ignore any other characters */ } } else { memset (buffer, 0, size); counter = 0; if (dummy == 0) printf ("\nreceived NULL!\n"); else printf ("\n\nGot EOF!\n"); sleep(10); c = '\r'; status = ERROR; } } buffer[counter] = 0; return status; } void* thread(void* dummy) { init_signals(); while (1) ; return NULL; } int main(int argc, char* argv[]) { pthread_t tid; pthread_create(&tid, NULL, &thread, NULL); while (1) { char buffer[200]; printf ("Prompt %d> ", i); get_input(buffer, sizeof(buffer)); // Give ourselves something to next... printf("Got "); // <<<<<<<<<<<<< Put breakpoint here printf("'%s'", buffer); printf("\n"); } pthread_join(tid,NULL); return 0; }