Linux c setitimer??÷??????
???????????? ???????[ 2016/2/2 11:46:23 ] ?????????????? Linux
??????linux c????С?setitimer?????????????????????????????????????????????????и?????????????÷???????????????????????÷???????????????????????????????
??????????????????????
????#include <sys/time.h>
????setitimer????????
????int setitimer(int which?? const struct itimerval *new_value??
????struct itimerval *old_value);
????????which??????????????????У?
????ITIMER_REAL?????????????????????????SIGALRM????
????ITIMER_VIRTUAL????y?????????????????????????????SIGVTALRM????
????ITIMER_PROF????y??????????o??????????????????????????SIGPROF????
??????????new_value??old_value???itimerval???壬??????itimerval???嶨?壺
????struct itimerval {
????struct timeval it_interval; /* next value */
????struct timeval it_value; /* current value */
????};
????struct timeval {
????time_t tv_sec; /* seconds */
????suseconds_t tv_usec; /* microseconds */
????};
????itimeval??????????timeval????????timeval????tv_sec??tv_usec???????????tv_se???tv_usec????(??1/1000000??)
???????е?new_value??????????????????????it_interval????????it_value??????????????????б????????setitimer???????ó???????1?????????SIGALRM??????????200?????????SIGALRM????
????settimer??????????????it_value????it_value????????????????????it_interval????????it_value????????????????
?????????????setitimer???????????????У?????????С?
????????it_value?0??????????????????????????it_value?????0??????it_interval???????????????????????????????????????)??
????old_value????????????ò?????????NULL???????????洢?????setitimer??????????new_value???
??????????????????????????
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
void signalHandler(int signo)
{
switch (signo){
case SIGALRM:
printf("Caught the SIGALRM signal!
");
break;
}
}
int main(int argc?? char *argv[])
{
signal(SIGALRM?? signalHandler);
struct itimerval new_value?? old_value;
new_value.it_value.tv_sec = 0;
new_value.it_value.tv_usec = 1;
new_value.it_interval.tv_sec = 0;
new_value.it_interval.tv_usec = 200000;
setitimer(ITIMER_REAL?? &new_value?? &old_value);
for(;;);
return 0;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11