打破這是我的代碼:使用的sigaction和報警脫離無限循環
#define _OPEN_SYS
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
volatile int footprint = 0;
void catcher(int signum) {
puts("inside signal catcher!");
alarm(0);
footprint = 1;
return;
}
main() {
printf("footprint=%d\n", footprint);
struct sigaction sact;
sigemptyset(&sact.sa_mask);
sact.sa_flags = 0;
sact.sa_handler = catcher;
if (footprint == 0) {
puts("the signal catcher never gained control");
sigaction(SIGALRM, &sact, NULL);
printf("before loop");
alarm(5); /* timer will pop in five seconds */
while (true);
} else
puts("the signal catcher gained control");
printf("after loop");
}
我的輸出是:
footprint=0
the signal catcher never gained control
before loopinside signal catcher!
和應用一直運行下去,我必須要想辦法打破這種循環,我使用類似的代碼來使sybase語句執行超時,因爲OCCI不支持超時。
也許你的意思while(footprint == 0); –