Re: Interval timers on Fedora

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

 



Douglas Phillipson wrote:


[snip]

My result on the timer issue is that a interval timer won't call its timeout function while msgrcv() is waiting for a message on a queue.

Regards

Doug P


Strange, it works for me. Try this!

Regards,

John


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

static int signal_cnt;

//--------------------------------------------------------------------------------

void catch_signal ( int ignored )
{
    ++ signal_cnt;
}

//--------------------------------------------------------------------------------

int main ( int argc, char **argv )
{
    // create msg queue

    int mqid;

    if ( ( mqid = msgget ( (key_t) 12345, IPC_CREAT | 0600 ) ) == -1 )
    {
        exit ( 1 );
    }

    // set a timer

    struct itimerval it;
    struct sigaction sa;

    memset ( &sa, 0, sizeof ( sa ) );
    sa.sa_handler = catch_signal;
    sigemptyset ( &sa.sa_mask );
    sa.sa_flags = SA_RESTART;
    sigaction ( SIGALRM, &sa, NULL );

    memset ( &it, 0, sizeof ( it ) );
    it.it_interval.tv_sec = 5;
    it.it_value.tv_sec = 5;

    if ( setitimer ( ITIMER_REAL, &it, NULL ) )
    {
        exit ( 1 );
    }

    struct msgbuf *msgp; ssize_t msz;

    msgp = malloc ( 512 );

    for ( ;; )
    {
        // get a message

        if ( ( msz = msgrcv ( mqid, msgp, 256, 0, 0 ) ) == -1 )
        {
             printf ( "msgrcv returned errno [%d]\n", errno );
        }

        fprintf ( stderr, "signal count [%d]\n", signal_cnt );
    }

    return 0;
}

--
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