Signal範例
Code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
static int loop = 1;
void alarm_handler(int a)
{
printf("Alarm!!!\n");
loop = 0;
}
int main(int argc, char *argv[])
{
signal(SIGALRM, alarm_handler);
/* you also can run via "killall -14 xxx" command */
alarm(9);
while(loop)
{
}
printf("Program exit!!!\n");
return 0;
}
Result:
Alarm!!!
Program exit!!!
沒有留言:
張貼留言