Skip to content

Instantly share code, notes, and snippets.

@bibiboot
Created September 17, 2013 06:01
Show Gist options
  • Save bibiboot/6590557 to your computer and use it in GitHub Desktop.
Save bibiboot/6590557 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <time.h>
#include <signal.h>
int handler();
void show_status();
int long_running_procedure( struct timespec time_sleep, struct timespec time_rem);
int status = 0;
int main(int argc, char *argv[])
{
struct timespec time_sleep, time_rem;
time_sleep.tv_sec = 3;
time_sleep.tv_nsec = 100;
//sigset(SIGINT, handler);
sigset(SIGINT, show_status);
long_running_procedure(time_sleep, time_rem);
}
int handler()
{
printf("Handler is called\n");
}
void show_status()
{
printf("Status = %d\n", status);
}
int long_running_procedure( struct timespec time_sleep, struct timespec time_rem)
{
while(1){
nanosleep(&time_sleep, &time_rem);
status=+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment