include time include signal int main sigevent event event sigev_notify

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <time.h>
#include <signal.h>
int main()
{
sigevent event;
event.sigev_notify = SIGEV_SIGNAL;
event.sigev_signo = SIGUSR1;
timer_t tid;
timer_create(clock_id, &event, &tid);
itime.it_value.tv_sec = 0;
itime.it_value.tv_nsec = 500000000;
itime.it_interval.tv_sec = 0;
itime.it_interval.tv_nsec = 500000000;
timer_settime(tid, 0, &itime, NULL)
}
void signal_handler(int signo, siginfo_t* info, void* other)
{
if (signo != SIGUSR1) return;
switch(info->si_code)
{
case SI_TIMER:
std::cout << "Handler!" << std::endl;
return;
}
std::cout << "How i did occure here?" << std::endl;
}