Skip to content

Instantly share code, notes, and snippets.

@ustbgaofan
Created April 19, 2013 15:32
Show Gist options
  • Save ustbgaofan/5421136 to your computer and use it in GitHub Desktop.
Save ustbgaofan/5421136 to your computer and use it in GitHub Desktop.
#include <signal.h>
#include <stdio.h>
#include <time.h>
static void sig_alrm(int); /* one handler for both signals */
time_t start,stop;
int main(void)
{
signal(SIGALRM,sig_alrm);
start = time(NULL);
for ( ; ; ){
sleep(4);
printf("[%ld] add an alarm\n",time(NULL)-start);
alarm(3);
}
}
static void sig_alrm(int signo) /* argument is signal number */
{
printf("[%ld] enter alram\n",time(NULL) - start);
sleep(5);
printf("[%ld] completed \n",time(NULL) - start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment