Re: Interval timers on Fedora

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




John Wendel wrote:



I'm not an expert on this stuff, but my understanding is that setitimer gives your process access to one of three predefined timers (REAL, VIRTUAL, and PROF) and only the REAL timer is actually useful. So your second call to setitimer is mucking up the settings from the first call.

See "man timer_create" for the POSIX timer stuff that lets you have lots of timers.

I recommend the O'REILLY book POSIX 4 by Bill Gallmeister for a good explanation of this fairly complicated topic.

Regards,

John


I just tried the following experiment and it worked fine with 4 timers! I must be doing something stupid in my other code...

#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <signal.h>
#include <sys/time.h>


void catch_signal1(int ignored);
void catch_signal2(int ignored);
void catch_signal3(int ignored);
void catch_signal4(int ignored);

void catch_signal1 (int ignored) {
   fprintf(stderr,"Timer 1 caught...\n");
}

void catch_signal2 (int ignored) {
   fprintf(stderr,"Timer 2 caught...\n");
}

void catch_signal3 (int ignored) {
   fprintf(stderr,"Timer 3 caught...\n");
}
void catch_signal4 (int ignored) {
   fprintf(stderr,"Timer 4 caught...\n");
}

main(int argc, char **argv) {

   start_timer1(1,catch_signal1);
   start_timer1(2,catch_signal2);
   start_timer1(3,catch_signal3);
   start_timer1(8,catch_signal4);
   while(1) {
      pause();
   }

}

pid_t start_timer1 (int interval, void(*func)(void)) {
    pid_t child;
    struct itimerval it;
    struct sigaction sa;


    if (!(child = fork())) {
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = func;
        sigemptyset(&sa.sa_mask);
        sa.sa_flags = SA_RESTART;

        sigaction(SIGALRM, &sa, NULL);
        memset(&it, 0, sizeof(it));
        it.it_interval.tv_sec = interval;
        it.it_value.tv_sec = interval;
        setitimer(ITIMER_REAL, &it, NULL);

        while (1) {
            pause();
        }
    }

    return child;
}

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux