Like Tree2Likes

Puzzled: SIGALRM signal handler doesn't install

This is a discussion on Puzzled: SIGALRM signal handler doesn't install within the C Programming forums, part of the General Programming Boards category; Hello. I already installed some signal handlers, but the one for SIGALRM doesn't install. Application follows default action and quits. ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    14

    Puzzled: SIGALRM signal handler doesn't install

    Hello.
    I already installed some signal handlers, but the one for SIGALRM doesn't install.
    Application follows default action and quits.
    Here is my code
    Code:
    #define INTERVAL 10
    static int s_interrupted = 0;
    
    
    static void s_signal_handler (int signal_value)
    {
        if (signal_value == SIGTERM || signal_value == SIGSTOP || signal_value == SIGINT)
            s_interrupted = 1;
        if (signal_value == SIGALRM)
        {
            //signal(SIGALRM,alarm_wakeup);
            printf("%d sec up partner, Wakeup!!!\n",INTERVAL);
        }
    }
    
    static void s_catch_signals (void)
    {
        struct sigaction action;
        action.sa_handler = s_signal_handler;
        action.sa_flags = 0;
        sigemptyset (&action.sa_mask);
        sigaction (SIGINT, &action, NULL);
        sigaction (SIGTERM, &action, NULL);
        sigaction (SIGALRM, &action, NULL);
    }
    
    
    
    void alarm_wakeup (int i)
    {
       signal(SIGALRM,alarm_wakeup);
       printf("%d sec up partner, Wakeup!!!\n",INTERVAL);
    }
    
    int main (void)
    {
        struct itimerval tout_val, check_val;
      
        tout_val.it_interval.tv_sec = 0;
        tout_val.it_interval.tv_usec = 0;
        tout_val.it_value.tv_sec = 10; /* set timer for "INTERVAL (10) seconds */
        tout_val.it_value.tv_usec = 0;
        //int myerr = setitimer(ITIMER_REAL, &tout_val,0);
    
        //signal(SIGALRM,alarm_wakeup); /* set the Alarm signal capture */
        s_catch_signals ();
        
       
        while (1) {
    
            if (s_interrupted == 1) {
                printf("\n");
    #if (MAIN_DEBUG)
                dbg_print(MAIN_PROC_NAME,"SIGINT interrupt received, killing node\n");
    #else
                printf("\n!!!!!    KILL NODE COMMAND RECEIVED    !!!!!\n\n");
    #endif
                break;
            }
     
            getitimer(ITIMER_REAL,&check_val);
            dbg_print(MAIN_PROC_NAME,"Timer check %ld, %ld, %ld, %ld\n",check_val.it_interval.tv_sec,check_val.it_interval.tv_usec,check_val.it_value.tv_sec,check_val.it_value.tv_usec);
            if (check_val.it_value.tv_usec == 0)
                alarm(10);
    
            s_sleep (1000);
    
    
        }
    
    
        return 0;
    }
    As you can see from the code I tried two ways of installing the handler:
    -standalone with call to signal(SIGALRM,alarm_wakeup);
    -integrated in the already existing signal handler

    No matter what after the timer expires the application quits.
    What am I doing wrong?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,481
    Well, hard to say without the complete code (how is s_sleep implemented?), but from the alarm() man page:
    Quote Originally Posted by man 2 alarm
    NOTES
    alarm() and setitimer(2) share the same timer; calls to one will interfere with use of the
    other.


    sleep(3) may be implemented using SIGALRM; mixing calls to alarm() and sleep(3) is a bad
    idea.

    Scheduling delays can, as ever, cause the execution of the process to be delayed by an
    arbitrary amount of time.
    alarm() doesn't play well with setitimer and sleep.

    Try setting up another signal handler, say for SIGUSR1, and make sure you can install and process that signal correctly (send a kill command with a SIGUSR1 to your program from the command line). Then you can make sure you are installing and setting up the signal handlers correctly.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    14
    Quote Originally Posted by anduril462 View Post
    Well, hard to say without the complete code (how is s_sleep implemented?), but from the alarm() man page:

    alarm() doesn't play well with setitimer and sleep.

    Try setting up another signal handler, say for SIGUSR1, and make sure you can install and process that signal correctly (send a kill command with a SIGUSR1 to your program from the command line). Then you can make sure you are installing and setting up the signal handlers correctly.
    The code for s_sleep is
    Code:
    //  Sleep for a number of milliseconds
    static void
    s_sleep (int msecs)
    {
    #if (defined (__WINDOWS__))
        Sleep (msecs);
    #else
        struct timespec t;
        t.tv_sec  =  msecs / 1000;
        t.tv_nsec = (msecs % 1000) * 1000000;
        nanosleep (&t, NULL);
    #endif
    }
    From the zhelpers.h of the ZeroMQ.

    I'll try your suggestion of a user defined signal.
    But the main cycle with the sleep and alarm works, as after each delay I can print the timer values correctly.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    >> static int s_interrupted = 0;
    This needs to be of type "volatile sig_atomic_t". See the third paragraph under "Application Usage" here: sigaction

    Also, "printf" is not listed as an "async-signal-safe" function: General Information

    I would also add error checking and reporting all all system calls.

    What is the end-goal you are trying to achieve? Perhaps there is a better way to achieve that goal that does not involve signal handling.

    gg

  5. #5
    Registered User
    Join Date
    Aug 2012
    Posts
    14
    Quote Originally Posted by Codeplug View Post
    >> static int s_interrupted = 0;
    This needs to be of type "volatile sig_atomic_t". See the third paragraph under "Application Usage" here: sigaction
    Will read, I'm not well educated in this matter to say the thruth.
    Edit: don't understand how this affects me.
    The effective handler does a compare and sets a variable, it doesn't call any non async-signal-safe functions (besides printf, and I know it shouldn't).
    Anyway the code is mostly taken from the ZMQ guide, so I assume it works.

    Quote Originally Posted by Codeplug View Post
    Also, "printf" is not listed as an "async-signal-safe" function: General Information
    Yeah know, but was just to try.

    Quote Originally Posted by Codeplug View Post
    I would also add error checking and reporting all all system calls.
    Don't know what error checking is, if you are not referring to compilation error, nor I know how to report all system calls (though I searched for it, maybe I did with the wrong terms as I couldn't find it).
    Edit: oh ok, you mean strace.
    Will try tomorrow, thanks for the hint!
    I couldn't believe I couldn't find it, I was sure it was somewhere :P

    Quote Originally Posted by Codeplug View Post
    What is the end-goal you are trying to achieve? Perhaps there is a better way to achieve that goal that does not involve signal handling.
    I'm using the ZeroMQ transport layer to create a mesh network between multiple simulation nodes on the same machine.
    The idea is to implement a cdma-like access method: every node would first listen for n seconds, if nothing comes through during that time, a further wait of a random number of seconds is issued after which the node becomes a server.
    During this second wait the node continues to listen.
    So the node that generates the smallest wait will become a server and announce itself, thus all the rest will receive and connect.

    So the ZMQ State Machine needs an async timer to achieve this.
    Are there other ways to achieve the same besides signals?
    On windows I would use a timer with a callback, but my understanding is that under linux there is a finite number of timers a thread can have, and the interrupt is always a signal.
    Last edited by erupter; 08-20-2012 at 04:32 PM.
    colleeng likes this.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    >> Edit: don't understand how this affects me.
    Quote Originally Posted by POSIX
    ... the behavior is undefined if the signal handler ... refers to any object other than errno with static storage duration other than by assigning a value to a static storage duration variable of type volatile sig_atomic_t.
    Only matters if you care about defined behavior according to Posix. If you had used signal(), then it would be undefined according to C/C++ standards as well.

    >> Don't know how to achieve it [error checking and reporting].
    Look up the function in the manual to see what constitutes an error. For example, sigaction() returns 0 on success. If something other than 0 is returned, you could call perror("sigaction") followed by exit().

    >> Are there other ways to achieve the same besides signals?
    Looks like zmq_poll() could be used to timeout while waiting for something to recv.

    gg

  7. #7
    Registered User
    Join Date
    Aug 2012
    Posts
    14
    Quote Originally Posted by Codeplug View Post
    >> Are there other ways to achieve the same besides signals?
    Looks like zmq_poll() could be used to timeout while waiting for something to recv.

    gg
    No it wouldn't work as zmq_poll takes microseconds for timeout, and I need seconds.

    Here is the trace
    Code:
    execve("./zeromq_ex1", ["./zeromq_ex1"], [/* 41 vars */]) = 0
    brk(0)                                  = 0x15b0000
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a77000
    access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/tls/x86_64/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib/tls/x86_64", 0x7fff45ba5ce0) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/tls/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib/tls", 0x7fff45ba5ce0) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/x86_64/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib/x86_64", 0x7fff45ba5ce0) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/usr/local/lib64/tls/x86_64/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib64/tls/x86_64", 0x7fff45ba5ce0) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/tls/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib64/tls", 0x7fff45ba5ce0) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/x86_64/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib64/x86_64", 0x7fff45ba5ce0) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libzmq.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/local/lib64", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
    fstat(3, {st_mode=S_IFREG|0644, st_size=98222, ...}) = 0
    mmap(NULL, 98222, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f8d21a5f000
    close(3)                                = 0
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/usr/lib/libzmq.so.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\305\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=240984, ...}) = 0
    mmap(NULL, 2336144, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d2161c000
    mprotect(0x7f8d21653000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d21852000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x36000) = 0x7f8d21852000
    close(3)                                = 0
    open("/usr/local/lib/libplayerc.so.3.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\231\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=190260, ...}) = 0
    mmap(NULL, 2255072, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d213f5000
    mprotect(0x7f8d2141a000, 2097152, PROT_NONE) = 0
    mmap(0x7f8d2161a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x25000) = 0x7f8d2161a000
    close(3)                                = 0
    open("/usr/local/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libpthread.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200l\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0755, st_size=135366, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a5e000
    mmap(NULL, 2212904, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d211d8000
    mprotect(0x7f8d211f0000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d213ef000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f8d213ef000
    mmap(0x7f8d213f1000, 13352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8d213f1000
    close(3)                                = 0
    open("/usr/local/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200\30\2\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0755, st_size=1802936, ...}) = 0
    mmap(NULL, 3917016, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d20e1b000
    mprotect(0x7f8d20fce000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d211cd000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b2000) = 0x7f8d211cd000
    mmap(0x7f8d211d3000, 17624, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8d211d3000
    close(3)                                = 0
    open("/usr/local/lib/libpgm-5.1.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libpgm-5.1.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/usr/lib/libpgm-5.1.so.0", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3608\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=297760, ...}) = 0
    mmap(NULL, 2410576, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d20bce000
    mprotect(0x7f8d20c16000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d20e15000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x47000) = 0x7f8d20e15000
    mmap(0x7f8d20e17000, 14416, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8d20e17000
    close(3)                                = 0
    open("/usr/local/lib/libuuid.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libuuid.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libuuid.so.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\25\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=18896, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a5d000
    mmap(NULL, 2113944, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d209c9000
    mprotect(0x7f8d209cd000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d20bcc000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f8d20bcc000
    close(3)                                = 0
    open("/usr/local/lib/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340!\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=31752, ...}) = 0
    mmap(NULL, 2128984, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d207c1000
    mprotect(0x7f8d207c8000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d209c7000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f8d209c7000
    close(3)                                = 0
    open("/usr/local/lib/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/usr/lib/x86_64-linux-gnu/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\241\5\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=962656, ...}) = 0
    mmap(NULL, 3142544, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d204c1000
    mprotect(0x7f8d205a3000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d207a2000, 40960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe1000) = 0x7f8d207a2000
    mmap(0x7f8d207ac000, 82832, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8d207ac000
    close(3)                                = 0
    open("/usr/local/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320(\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=88384, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a5c000
    mmap(NULL, 2184216, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d202ab000
    mprotect(0x7f8d202c0000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d204bf000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x7f8d204bf000
    close(3)                                = 0
    open("/usr/local/lib/libplayerinterface.so.3.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\237\2\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=495648, ...}) = 0
    mmap(NULL, 2498312, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d20049000
    mprotect(0x7f8d200a6000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d202a5000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5c000) = 0x7f8d202a5000
    close(3)                                = 0
    open("/usr/local/lib/libplayerwkb.so.3.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\7\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=16560, ...}) = 0
    mmap(NULL, 2109512, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d1fe45000
    mprotect(0x7f8d1fe48000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d20047000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f8d20047000
    close(3)                                = 0
    open("/usr/local/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libm.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0pU\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=1022320, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a5b000
    mmap(NULL, 3117352, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d1fb4b000
    mprotect(0x7f8d1fc44000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d1fe43000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf8000) = 0x7f8d1fe43000
    close(3)                                = 0
    open("/usr/local/lib/libz.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/libz.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libz.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libz.so.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=92720, ...}) = 0
    mmap(NULL, 2187824, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d1f934000
    mprotect(0x7f8d1f94a000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d1fb49000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7f8d1fb49000
    close(3)                                = 0
    open("/usr/local/lib/libplayerjpeg.so.3.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\r\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=13938, ...}) = 0
    mmap(NULL, 2105568, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d1f731000
    mprotect(0x7f8d1f733000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d1f932000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f8d1f932000
    close(3)                                = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a5a000
    open("/usr/local/lib/libplayercommon.so.3.1", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \7\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=8239, ...}) = 0
    mmap(NULL, 2101336, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d1f52f000
    mprotect(0x7f8d1f530000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d1f72f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x7f8d1f72f000
    close(3)                                = 0
    open("/usr/local/lib/libjpeg.so.8", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/libjpeg.so.8", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib/libjpeg.so.8", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libjpeg.so.8", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/usr/lib/x86_64-linux-gnu/libjpeg.so.8", O_RDONLY|O_CLOEXEC) = 3
    read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 @\0\0\0\0\0\0"..., 832) = 832
    fstat(3, {st_mode=S_IFREG|0644, st_size=260872, ...}) = 0
    mmap(NULL, 2421480, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8d1f2df000
    mprotect(0x7f8d1f31d000, 2097152, PROT_NONE) = 0
    mmap(0x7f8d1f51d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3e000) = 0x7f8d1f51d000
    mmap(0x7f8d1f51f000, 62184, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8d1f51f000
    close(3)                                = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a59000
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a58000
    mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a56000
    arch_prctl(ARCH_SET_FS, 0x7f8d21a56780) = 0
    mprotect(0x7f8d211cd000, 16384, PROT_READ) = 0
    mprotect(0x7f8d1f51d000, 4096, PROT_READ) = 0
    mprotect(0x7f8d1f72f000, 4096, PROT_READ) = 0
    mprotect(0x7f8d1f932000, 4096, PROT_READ) = 0
    mprotect(0x7f8d1fb49000, 4096, PROT_READ) = 0
    mprotect(0x7f8d1fe43000, 4096, PROT_READ) = 0
    mprotect(0x7f8d20047000, 4096, PROT_READ) = 0
    mprotect(0x7f8d202a5000, 4096, PROT_READ) = 0
    mprotect(0x7f8d204bf000, 4096, PROT_READ) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a55000
    mprotect(0x7f8d207a2000, 32768, PROT_READ) = 0
    mprotect(0x7f8d213ef000, 4096, PROT_READ) = 0
    mprotect(0x7f8d209c7000, 4096, PROT_READ) = 0
    mprotect(0x7f8d20bcc000, 4096, PROT_READ) = 0
    mprotect(0x7f8d20e15000, 4096, PROT_READ) = 0
    mprotect(0x7f8d2161a000, 4096, PROT_READ) = 0
    mprotect(0x7f8d21852000, 16384, PROT_READ) = 0
    mprotect(0x604000, 4096, PROT_READ)     = 0
    mprotect(0x7f8d21a79000, 4096, PROT_READ) = 0
    munmap(0x7f8d21a5f000, 98222)           = 0
    set_tid_address(0x7f8d21a56a50)         = 26109
    set_robust_list(0x7f8d21a56a60, 0x18)   = 0
    futex(0x7fff45ba65dc, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 7f8d21a56780) = -1 EAGAIN (Resource temporarily unavailable)
    rt_sigaction(SIGRTMIN, {0x7f8d211de750, [], SA_RESTORER|SA_SIGINFO, 0x7f8d211e7cb0}, NULL, 8) = 0
    rt_sigaction(SIGRT_1, {0x7f8d211de7e0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f8d211e7cb0}, NULL, 8) = 0
    rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
    getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
    brk(0)                                  = 0x15b0000
    brk(0x15d1000)                          = 0x15d1000
    open("/proc/self/auxv", O_RDONLY)       = 3
    fstat(3, {st_mode=S_IFREG|0400, st_size=0, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a76000
    read(3, "!\0\0\0\0\0\0\0\0\200\274E\377\177\0\0\20\0\0\0\0\0\0\0\377\373\353\277\0\0\0\0"..., 1024) = 304
    rt_sigaction(SIGINT, {0x403212, [], SA_RESTORER, 0x7f8d211e7cb0}, NULL, 8) = 0
    rt_sigaction(SIGTERM, {0x403212, [], SA_RESTORER, 0x7f8d211e7cb0}, NULL, 8) = 0
    rt_sigaction(SIGALRM, {0x403212, [], SA_RESTORER, 0x7f8d211e7cb0}, NULL, 8) = 0
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 0}}) = 0
    open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 4
    fstat(4, {st_mode=S_IFREG|0644, st_size=2652, ...}) = 0
    fstat(4, {st_mode=S_IFREG|0644, st_size=2652, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a75000
    read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\6\0\0\0\6\0\0\0\0"..., 4096) = 2652
    lseek(4, -1701, SEEK_CUR)               = 951
    read(4, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\10\0\0\0\10\0\0\0\0"..., 4096) = 1701
    close(4)                                = 0
    munmap(0x7f8d21a75000, 4096)            = 0
    fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a75000
    write(1, "[10:19:37.875811  Main] Timer ch"..., 47) = 47
    alarm(10)                               = 0
    nanosleep({1, 0}, NULL)                 = 0
    open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 4
    read(4, "0-7\n", 8192)                  = 4
    close(4)                                = 0
    openat(AT_FDCWD, "/sys/devices/system/cpu", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4
    getdents(4, /* 20 entries */, 32768)    = 576
    getdents(4, /* 0 entries */, 32768)     = 0
    close(4)                                = 0
    sched_getaffinity(26109, 128, {ff, 0, 0, 0}) = 32
    open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 4
    fstat(4, {st_mode=S_IFREG|0644, st_size=513, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a74000
    read(4, "# /etc/nsswitch.conf\n#\n# Example"..., 4096) = 513
    read(4, "", 4096)                       = 0
    close(4)                                = 0
    munmap(0x7f8d21a74000, 4096)            = 0
    open("/usr/local/lib/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 4
    fstat(4, {st_mode=S_IFREG|0644, st_size=98222, ...}) = 0
    mmap(NULL, 98222, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7f8d21a3d000
    close(4)                                = 0
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib/x86_64-linux-gnu/tls/x86_64", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib/x86_64-linux-gnu/tls", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib/x86_64-linux-gnu/x86_64", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/x86_64-linux-gnu/tls/x86_64", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/usr/lib/x86_64-linux-gnu/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/x86_64-linux-gnu/tls", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/usr/lib/x86_64-linux-gnu/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/x86_64-linux-gnu/x86_64", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/usr/lib/x86_64-linux-gnu/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=36864, ...}) = 0
    open("/lib/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib/tls/x86_64", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/lib/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib/tls", 0x7fff45ba39b0)        = -1 ENOENT (No such file or directory)
    open("/lib/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib/x86_64", 0x7fff45ba39b0)     = -1 ENOENT (No such file or directory)
    open("/lib/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    open("/usr/lib/tls/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/tls/x86_64", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/usr/lib/tls/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/tls", 0x7fff45ba39b0)    = -1 ENOENT (No such file or directory)
    open("/usr/lib/x86_64/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/x86_64", 0x7fff45ba39b0) = -1 ENOENT (No such file or directory)
    open("/usr/lib/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    stat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=45056, ...}) = 0
    munmap(0x7f8d21a3d000, 98222)           = 0
    open("/usr/local/lib/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/usr/local/lib64/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 4
    fstat(4, {st_mode=S_IFREG|0644, st_size=98222, ...}) = 0
    mmap(NULL, 98222, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7f8d21a3d000
    close(4)                                = 0
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    open("/lib/x86_64-linux-gnu/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 4
    read(4, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@!\0\0\0\0\0\0"..., 832) = 832
    fstat(4, {st_mode=S_IFREG|0644, st_size=52120, ...}) = 0
    mmap(NULL, 2148472, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) = 0x7f8d1f0d2000
    mprotect(0x7f8d1f0de000, 2093056, PROT_NONE) = 0
    mmap(0x7f8d1f2dd000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 4, 0xb000) = 0x7f8d1f2dd000
    close(4)                                = 0
    mprotect(0x7f8d1f2dd000, 4096, PROT_READ) = 0
    munmap(0x7f8d21a3d000, 98222)           = 0
    open("/etc/protocols", O_RDONLY|O_CLOEXEC) = 4
    fstat(4, {st_mode=S_IFREG|0644, st_size=2933, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a74000
    read(4, "# Internet (IP) protocols\n#\n# Up"..., 4096) = 2933
    read(4, "", 4096)                       = 0
    close(4)                                = 0
    munmap(0x7f8d21a74000, 4096)            = 0
    open("/proc/cpuinfo", O_RDONLY)         = 4
    fstat(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a74000
    read(4, "processor\t: 0\nvendor_id\t: Genuin"..., 1024) = 1024
    close(4)                                = 0
    munmap(0x7f8d21a74000, 4096)            = 0
    socketpair(PF_FILE, SOCK_STREAM, 0, [4, 5]) = 0
    fcntl(4, F_GETFL)                       = 0x2 (flags O_RDWR)
    fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
    fcntl(5, F_GETFL)                       = 0x2 (flags O_RDWR)
    fcntl(5, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
    socketpair(PF_FILE, SOCK_STREAM, 0, [6, 7]) = 0
    fcntl(6, F_GETFL)                       = 0x2 (flags O_RDWR)
    fcntl(6, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
    fcntl(7, F_GETFL)                       = 0x2 (flags O_RDWR)
    fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
    epoll_create(1)                         = 8
    epoll_ctl(8, EPOLL_CTL_ADD, 7, {0, {u32=22745952, u64=22745952}}) = 0
    epoll_ctl(8, EPOLL_CTL_MOD, 7, {EPOLLIN, {u32=22745952, u64=22745952}}) = 0
    mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f8d1e8d1000
    mprotect(0x7f8d1e8d1000, 4096, PROT_NONE) = 0
    clone(child_stack=0x7f8d1f0d0f70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f8d1f0d19d0, tls=0x7f8d1f0d1700, child_tidptr=0x7f8d1f0d19d0) = 26110
    socketpair(PF_FILE, SOCK_STREAM, 0, [9, 10]) = 0
    fcntl(9, F_GETFL)                       = 0x2 (flags O_RDWR)
    fcntl(9, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
    fcntl(10, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    epoll_create(1)                         = 11
    epoll_ctl(11, EPOLL_CTL_ADD, 10, {0, {u32=22745984, u64=22745984}}) = 0
    epoll_ctl(11, EPOLL_CTL_MOD, 10, {EPOLLIN, {u32=22745984, u64=22745984}}) = 0
    mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f8d1e0d0000
    mprotect(0x7f8d1e0d0000, 4096, PROT_NONE) = 0
    clone(child_stack=0x7f8d1e8cff70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f8d1e8d09d0, tls=0x7f8d1e8d0700, child_tidptr=0x7f8d1e8d09d0) = 26111
    socketpair(PF_FILE, SOCK_STREAM, 0, [12, 13]) = 0
    fcntl(12, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(12, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    fcntl(13, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(13, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    socketpair(PF_FILE, SOCK_STREAM, 0, [14, 15]) = 0
    fcntl(14, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(14, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    fcntl(15, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(15, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    socket(PF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 16
    setsockopt(16, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
    fcntl(16, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(16, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    bind(16, {sa_family=AF_INET, sin_port=htons(5555), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
    listen(16, 100)                         = 0
    sendto(9, "\0", 1, 0, NULL, 0)          = 1
    sendto(14, "\0", 1, 0, NULL, 0)         = 1
    write(1, "[10:19:38.883339  0MQ Lib] Bindi"..., 63) = 63
    socketpair(PF_FILE, SOCK_STREAM, 0, [17, 18]) = 0
    fcntl(17, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(17, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    fcntl(18, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(18, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    socket(PF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 19
    setsockopt(19, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
    fcntl(19, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(19, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
    bind(19, {sa_family=AF_INET, sin_port=htons(5556), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
    listen(19, 100)                         = 0
    sendto(9, "\0", 1, 0, NULL, 0)          = 1
    sendto(17, "\0", 1, 0, NULL, 0)         = 1
    write(1, "[10:19:38.883857  0MQ Lib] Bindi"..., 63) = 63
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={8, 992451}}) = 0
    write(1, "[10:19:38.883943  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    mmap(NULL, 368640, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d219fb000
    mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d1d8cf000
    mmap(NULL, 33558528, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d15fff000
    mmap(NULL, 33558528, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d13ffe000
    socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 20
    socket(PF_NETLINK, SOCK_RAW, 0)         = 21
    bind(21, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
    getsockname(21, {sa_family=AF_NETLINK, pid=26109, groups=00000000}, [12]) = 0
    sendto(21, "\24\0\0\0\26\0\1\3\233D3P\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
    recvmsg(21, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"0\0\0\0\24\0\2\0\233D3P\375e\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 108
    recvmsg(21, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"@\0\0\0\24\0\2\0\233D3P\375e\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 128
    recvmsg(21, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0\233D3P\375e\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
    close(21)                               = 0
    open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 21
    fstat(21, {st_mode=S_IFREG|0644, st_size=172, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a74000
    read(21, "# Dynamic resolv.conf(5) file fo"..., 4096) = 172
    read(21, "", 4096)                      = 0
    close(21)                               = 0
    munmap(0x7f8d21a74000, 4096)            = 0
    uname({sys="Linux", node="FCD-Ubuntu", ...}) = 0
    socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 21
    connect(21, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
    close(21)                               = 0
    socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 21
    connect(21, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
    close(21)                               = 0
    open("/etc/host.conf", O_RDONLY|O_CLOEXEC) = 21
    fstat(21, {st_mode=S_IFREG|0644, st_size=92, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a74000
    read(21, "# The \"order\" line is only used "..., 4096) = 92
    read(21, "", 4096)                      = 0
    close(21)                               = 0
    munmap(0x7f8d21a74000, 4096)            = 0
    futex(0x7f8d211d5b40, FUTEX_WAKE_PRIVATE, 2147483647) = 0
    open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 21
    fstat(21, {st_mode=S_IFREG|0644, st_size=225, ...}) = 0
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d21a74000
    read(21, "127.0.0.1\tlocalhost\n127.0.1.1\tFC"..., 4096) = 225
    read(21, "", 4096)                      = 0
    close(21)                               = 0
    munmap(0x7f8d21a74000, 4096)            = 0
    setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={5, 0}}, NULL) = 0
    rt_sigaction(SIGALRM, NULL, {0x403212, [], SA_RESTORER, 0x7f8d211e7cb0}, 8) = 0
    rt_sigaction(SIGALRM, {0x7f8d213ff004, [], SA_RESTORER, 0x7f8d211e7cb0}, NULL, 8) = 0
    connect(20, {sa_family=AF_INET, sin_port=htons(6665), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
    setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
    rt_sigaction(SIGALRM, {SIG_DFL, [], SA_RESTORER|SA_RESTART, 0x7f8d211e7cb0}, NULL, 8) = 0
    fcntl(20, F_GETFL)                      = 0x2 (flags O_RDWR)
    fcntl(20, F_SETFL, O_RDWR)              = 0
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 2000) = 1 ([{fd=20, revents=POLLIN}])
    recvfrom(20, "Player v.3.1.0-svn\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32, 0, NULL, NULL) = 32
    sendto(20, "\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\3\0\0\0\5A\324\f\321&\371\322\366"..., 44, 0, NULL, 0) = 44
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 0 (Timeout)
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 0 (Timeout)
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 0 (Timeout)
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 0 (Timeout)
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 0 (Timeout)
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 0 (Timeout)
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 0 (Timeout)
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 10) = 1 ([{fd=20, revents=POLLIN}])
    poll([{fd=20, events=POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL}], 1, 5000) = 1 ([{fd=20, revents=POLLIN}])
    recvfrom(20, "\1\0\0\177\0\0\32\t\0\0\0\1\0\0\0\0\0\0\0\4\0\0\0\5@Z&fffff"..., 40, 0, NULL, NULL) = 40
    write(2, "playerc warning   : warning : [P"..., 95) = 95
    poll([{fd=15, events=POLLIN}], 1, 0)    = 1 ([{fd=15, revents=POLLIN}])
    poll([{fd=15, events=POLLIN}], 1, 0)    = 1 ([{fd=15, revents=POLLIN}])
    recvfrom(15, "\0", 1, 0, NULL, NULL)    = 1
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 0}}) = 0
    write(1, "[10:19:39.978511  Main] Timer ch"..., 47) = 47
    alarm(10)                               = 0
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={8, 999252}}) = 0
    write(1, "[10:19:40.979438  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={7, 998164}}) = 0
    write(1, "[10:19:41.980530  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={6, 994399}}) = 0
    write(1, "[10:19:42.984220  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={5, 993893}}) = 0
    write(1, "[10:19:43.984721  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={4, 992894}}) = 0
    write(1, "[10:19:44.985730  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={3, 992081}}) = 0
    write(1, "[10:19:45.986580  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={2, 991387}}) = 0
    write(1, "[10:19:46.987302  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={1, 990567}}) = 0
    write(1, "[10:19:47.988079  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = 0
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    poll([{fd=15, events=POLLIN}], 1, 0)    = 0 (Timeout)
    getitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 989565}}) = 0
    write(1, "[10:19:48.989123  Main] Timer ch"..., 52) = 52
    nanosleep({1, 0}, NULL)                 = ? ERESTART_RESTARTBLOCK (To be restarted)
    --- SIGALRM (Alarm clock) @ 0 (0) ---
    +++ killed by SIGALRM +++
    I can't get much out of it in the way of useful information though; i can clearly see the three SIGACTION calls and the final SIGALRM.


    Here is the modified code
    Code:
    #include <zmq.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <string.h>
    #include <sys/time.h>
    #include "zhelpers.h"
    #include <czmq.h>
    #include <signal.h>
    #include <unistd.h>
    #include "player_manager.h"
    #include "options.h"
    #include "zmq_manager.h"
    
    #define INTERVAL 10
    volatile sig_atomic_t s_interrupted = 0;
    volatile sig_atomic_t alarm_expired = 0;
    
    static void s_signal_handler (int signal_value)
    {
        if (signal_value == SIGTERM || signal_value == SIGSTOP || signal_value == SIGINT)
            s_interrupted = 1;
        if (signal_value == SIGALRM)
            //signal(SIGALRM,alarm_wakeup);
            alarm_expired = 1;
    }
    
    static void s_catch_signals (void)
    {
        struct sigaction action;
        action.sa_handler = s_signal_handler;
        action.sa_flags = 0;
        sigemptyset (&action.sa_mask);
        sigaction (SIGINT, &action, NULL);
        sigaction (SIGTERM, &action, NULL);
        sigaction (SIGALRM, &action, NULL);
    }
    
    
    
    void alarm_wakeup (int i)
    {
       alarm_expired = 1;
    }
    
    int main (void)
    {
        struct itimerval tout_val, check_val;
      
        tout_val.it_interval.tv_sec = 0;
        tout_val.it_interval.tv_usec = 0;
        tout_val.it_value.tv_sec = INTERVAL; /* set timer for "INTERVAL (10) seconds */
        tout_val.it_value.tv_usec = 0;
        if (setitimer(ITIMER_REAL, &tout_val,0) != 0)
        {
            perror("setitimer");
            exit(0);
        }
        if (signal(SIGALRM,alarm_wakeup) != 0) /* set the Alarm signal capture */
        {
            perror("signal");
            exit(0);        
        }
        s_catch_signals ();
        
       
        while (1) {
    
            if (s_interrupted == 1) {
                printf("\n");
    #if (MAIN_DEBUG)
                dbg_print(MAIN_PROC_NAME,"SIGINT interrupt received, killing node\n");
    #else
                printf("\n!!!!!    KILL NODE COMMAND RECEIVED    !!!!!\n\n");
    #endif
                break;
            }
            Player_Manager();
            // Wait for next request from client
    
            if (PLAYER_MANAGER_STATE == PL_IDLE)
                Player_Manager_Connect();
           
            ZMQ_Manager();        
            getitimer(ITIMER_REAL,&check_val);
            dbg_print(MAIN_PROC_NAME,"Timer check %ld, %ld, %ld, %ld\n",check_val.it_interval.tv_sec,check_val.it_interval.tv_usec,check_val.it_value.tv_sec,check_val.it_value.tv_usec);
            if (check_val.it_value.tv_usec == 0)
                if (setitimer(ITIMER_REAL, &tout_val,0) != 0)
                {
                    perror("setitimer");
                    exit(0);
                }
                //alarm(INTERVAL);
            // Do some 'work'
            
            if (alarm_expired)
            {
                printf("%d sec up partner, Wakeup!!!\n",INTERVAL);
                alarm_expired = 0;
                //alarm(INTERVAL);
                
            }
            s_sleep (1000);
    
    
        }
        // We never get here but if we did, this would be how we end
        Player_Manager_Disconnect();
        ZMQ_Manager_Disconnect();
    
        return 0;
    }
    It still has the very same behavior.
    I believe I have included error checking on system calls correctly, still the SIGALRM event kills the app instead of being handled.
    I'll try timer_create().

  8. #8
    Registered User
    Join Date
    Aug 2012
    Posts
    14
    Quote Originally Posted by erupter View Post
    I'll try timer_create().
    I am finally able to achieve what I intended by using timer_create() with SIGUSR1.

    Correct me if I'm wrong: does this mean I can't have more than 2 custom signals per thread?

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    >> No it wouldn't work as zmq_poll takes microseconds for timeout, and I need seconds.
    If only there were a way to convert one to the other.....then zmq_poll would be the ideal solution.

    Also according to Posix, you shouldn't use both signal() and sigation() to control the same signal in a process.

    gg

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    14
    Quote Originally Posted by Codeplug View Post
    >> No it wouldn't work as zmq_poll takes microseconds for timeout, and I need seconds.
    If only there were a way to convert one to the other.....then zmq_poll would be the ideal solution.

    Also according to Posix, you shouldn't use both signal() and sigation() to control the same signal in a process.

    gg
    You are surely well informed about POSIX, but it seems to me you aren't keen on actually helping me solve my problem: pointing out where I don't adhere to POSIX standards, and what other standard things I don't do and should, doesn't really help me.

    By doing this you loose sight of my actual problem which is why my signal handler doesn't install or better doesn't get used, as it does indeed install from what I can understand of trace (by the way you didn't even comment on that).

    Also by reading the description I posted of the end result of this endeavour you should have understood this is nowhere near the final code, rather it's an oversimplified test bench for some functionality.
    I could surely put 10^7 in the timeout parameter of the zmq_poll call thanks, I know how to convert between milli, micro, nano and all the rest, but that would block and would thus render the poll technique kind of useless, wouldn't it?

    So how about stopping being picky about my not knowing enough about POSIX and actually start helping on the real matter?
    I can always learn better coding manners later when things actually work.

    But thanks anyway, I got away with SIGUSR1 and it's working nicely.

  11. #11
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    >> but that would block and would thus render the poll technique kind of useless, wouldn't it?
    I don't see how calling "zmq_poll" would "render the poll technique useless". Does your code need to "poll" something other than a file descriptor or socket? The whole point of zmq_poll is to allow you to "poll" a set of file descriptors and sockets efficiently. Hard spinning in a loop is the worst thing you could do.

    I think you would be better served if we fleshed out why you think zmq_poll isn't appropriate or wouldn't work for you. At this point, I believe it's the better and appropriate solution compared to signals.

    gg

  12. #12
    Registered User
    Join Date
    Aug 2012
    Posts
    14
    Quote Originally Posted by Codeplug View Post
    >> but that would block and would thus render the poll technique kind of useless, wouldn't it?
    I don't see how calling "zmq_poll" would "render the poll technique useless". Does your code need to "poll" something other than a file descriptor or socket? The whole point of zmq_poll is to allow you to "poll" a set of file descriptors and sockets efficiently. Hard spinning in a loop is the worst thing you could do.

    I think you would be better served if we fleshed out why you think zmq_poll isn't appropriate or wouldn't work for you. At this point, I believe it's the better and appropriate solution compared to signals.

    gg
    Maybe I wasn't clear enough last time: this is a barebone testbed.

    Ok so you want to know what I have to do: the entire application manages a robot, with sensors, map building, odometry, state estimation.
    The ZMQ part is only to communicate with other robots.
    Do you really need to know the specifics of what I have to do, to believe that blocking doesn't suit my needs?

    Only way I could use the timeout of the poll call is by going multi-thread, but then I'd have to create another inter-thread communication channel and protocol for the ZMQ thread and the rest.
    Doesn't really sound like a good idea to me.
    Or better: I can't be bothered to dedicate that much time to such a useless endeavour if I can just design this thing to do everything inside one thread.

  13. #13
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    >> Only way I could use the timeout of the poll call is by going multi-thread ...
    That makes no sense to me. Could you explain to us laypeople why that is?

    >> I think you would be better served if we fleshed out why you think zmq_poll isn't appropriate or wouldn't work for you.

    gg

  14. #14
    Registered User
    Join Date
    Aug 2012
    Posts
    14
    Quote Originally Posted by Codeplug View Post
    >> Only way I could use the timeout of the poll call is by going multi-thread ...
    That makes no sense to me. Could you explain to us laypeople why that is?
    Either I'm missing something really stupid here, or you refuse to see my point of view. Or worse you're making fun of me.

    Why would that be? Because otherwise every time I polled the sockets, I'd have a call blocking the main loop.
    Since the main loop does poll all the STMs, if anyone stuck all the others would wait for it, so effectively the entire program would be stuck.
    This is simple stupid really, do I even have to tell you?

    Only way I know to let the poll call block without hindering the rest of the program, is to let it run in its own thread where it could block safely.

    Instead of asking me times and again how do I think, why don't you provide an example (any example really) of how you would do it?

  15. #15
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    >> Because otherwise every time I polled the sockets, I'd have a call blocking the main loop.
    No, you wouldn't.
    s_sleep(1000); // this blocks for 1 second
    zmq_poll(items, 1000000); // this blocks for a maximum of 1 sec

    The difference? You're not stuck in a dumb sleep call when there could be a socket that is ready to be read/written.

    Quote Originally Posted by erupter
    The idea is to implement a cdma-like access method: every node would first listen for n seconds, if nothing comes through during that time, a further wait of a random number of seconds is issued after which the node becomes a server.
    During this second wait the node continues to listen.
    So the node that generates the smallest wait will become a server and announce itself, thus all the rest will receive and connect.
    It seems to me that those two waits can be achieved via zmq_poll().

    Do you have "other code" that must be run during these two wait periods?

    "No" - then the first zmq_poll can wait for n seconds, and the second zmq_poll can wait for the random N seconds. Or if possible, one zmq_poll for n + N seconds.

    "Yes" - then adjust the zmq_poll timeout accordingly - run the "other code" during the timeouts - maintain time-elapsed in order detect the "final timeout" indicating that the client should become the server. This is the typical methodology for "multiplexing" things without adding threads.

    gg

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. signal handler does not print
    By barramundi9 in forum C Programming
    Replies: 4
    Last Post: 07-27-2011, 11:20 PM
  2. Signal handler for assert()
    By jeffcobb in forum Linux Programming
    Replies: 17
    Last Post: 06-10-2010, 08:36 PM
  3. Signal handler function - pointer to this gets lost
    By maus in forum C++ Programming
    Replies: 1
    Last Post: 07-01-2009, 09:10 AM
  4. using a signal handler to kill processes
    By dinjas in forum C Programming
    Replies: 2
    Last Post: 03-16-2005, 11:58 AM
  5. signal handler
    By falconetti in forum C Programming
    Replies: 1
    Last Post: 02-21-2002, 06:54 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21