시그널 함수 등록할 때 주로 사용하는 시그널은 ctrl+c 더군요..
다른 시그널은 없나요? 가령 Esc키 같은 것..
사용자가 재정의 해서 사용할 수 있는 시그널 추천 좀 부탁합니다..
아니면 일정한 시간마다 특정 함수를 호출할 수 있는 시간함수가 있다면 소개 해주세요.
signal.h 보세요 수두룩 하게 있습니다. 아마 원하는건 다 있습니다.
상당히 게으르군요. 여기서도 제가 답변한게 많이 존재하는데요. 검색을 해보니 수십개의 예제가 있더군요.
그중 예전에 제가 한 답변중 timer(setitimer)에대한 부분을 옮깁니다. 개인적인 질문을 작성하기 보단 스스로 찾아보는 노력이 필요하네요.
############################################################ #include #include #include
void sigalrm(int sig) { struct timeval tm;
gettimeofday(&tm, NULL); printf("sigal call [%d], time[%d.%d]\n", sig, tm.tv_sec, tm.tv_usec); }
int main() { int k; struct itimerval ival, oval; struct sigaction si, so;
memset(&si, 0x00, sizeof(si)); memset(&so, 0x00, sizeof(so)); si.sa_handler = sigalrm; sigaction(SIGALRM, &si, &so);
memset(&ival, 0x00, sizeof(ival)); memset(&oval, 0x00, sizeof(oval));
ival.it_interval.tv_usec = 10000; ival.it_value.tv_sec = 5; setitimer(ITIMER_REAL, &ival, &oval);
for( k = 0; k < 10; k++) { sleep(2); printf("Test time [%d]\n", time(NULL)); }
}
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
Re: 시그널 함수 등록
signal.h 보세요 수두룩 하게 있습니다.
아마 원하는건 다 있습니다.
Re^2: 시그널 함수 등록
상당히 게으르군요. 여기서도 제가 답변한게 많이 존재하는데요.
검색을 해보니 수십개의 예제가 있더군요.
그중 예전에 제가 한 답변중 timer(setitimer)에대한 부분을 옮깁니다.
개인적인 질문을 작성하기 보단 스스로 찾아보는 노력이 필요하네요.
############################################################
#include
#include
#include
void sigalrm(int sig)
{
struct timeval tm;
gettimeofday(&tm, NULL);
printf("sigal call [%d], time[%d.%d]\n", sig, tm.tv_sec,
tm.tv_usec);
}
int main()
{
int k;
struct itimerval ival, oval;
struct sigaction si, so;
memset(&si, 0x00, sizeof(si));
memset(&so, 0x00, sizeof(so));
si.sa_handler = sigalrm;
sigaction(SIGALRM, &si, &so);
memset(&ival, 0x00, sizeof(ival));
memset(&oval, 0x00, sizeof(oval));
ival.it_interval.tv_usec = 10000;
ival.it_value.tv_sec = 5;
setitimer(ITIMER_REAL, &ival, &oval);
for( k = 0; k < 10; k++) {
sleep(2);
printf("Test time [%d]\n", time(NULL));
}
}
댓글 달기