Signal Handlers using sigwait


 
Thread Tools Search this Thread
Top Forums Programming Signal Handlers using sigwait
# 1  
Old 08-17-2010
Signal Handlers using sigwait

After an extensive search, I haven't found a definitive answer to my question. "And what is your question you frackking noob", you may ask. Ok, here goes: When using sigwait to wait for SIGUSR1 or SIGUSR2, can you have it trigger a signal handler? The following code did NOT, and the example I got it from said it did not. But WHY did it not? Can I make it call a signal handler?

Code:
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>

extern int errno;

void catcher( int sig ) {
    printf( "Signal catcher called for signal %d\n", sig );
}

void timestamp( char *str ) 
{
    time_t t;
    time( T );
    printf( "The time %s is %s\n", str, ctime(T) );
}

int main( int argc, char *argv[] ) 
{
    struct sigaction sigact;
    sigset_t waitset;
    int sig;
    int result = 0;

    sigemptyset( &sigact.sa_mask );
    sigact.sa_flags = 0;
    sigact.sa_handler = catcher;

    sigaction( SIGUSR1, &sigact, NULL );
    sigaction( SIGUSR2, &sigact, NULL );
    sigaction( SIGALRM, &sigact, NULL );
    sigaction( SIGHUP,  &sigact, NULL );

    sigemptyset( &waitset );
    sigaddset( &waitset, SIGUSR1);
    sigaddset( &waitset, SIGUSR2);
    sigaddset( &waitset, SIGALRM);
    sigaddset( &waitset, SIGHUP);

    

    sigprocmask( SIG_BLOCK, &waitset, NULL );

    while(1)
    {
        timestamp( "before sigwait()" );
        result = sigwait(&saitset, &sig) ;
        if(result == 0)
        {
            printf( "sigwait() returned for signal %d\n", sig );
        else 
        {
            printf( "sigwait() returned error number %d\n", errno );
            perror( "sigwait() function failed\n" );
        }

        timestamp( "after sigwait()" );
    }
    return( result );
}

A similar setup with sigsuspend DOES call the handler "catcher". If it is not supposed to be able to have a handler using sigwait, can you point me to the appropriate documentation?

D. Scruggs
# 2  
Old 08-21-2010
What platform did you test this ?
# 3  
Old 08-21-2010
Here is something that may help you - sigwait
It says:
Quote:
The sigwait() function selects a pending signal from set, atomically clears it from the system's set of pending signals ...
So it may be that the system checks for any process (/thread) waiting on a signal (via sigwait(2)) and if it finds one it returns after deleting the pending signal (from system's set), and after doing this operation it looks for the handler of the remaining signals.
But I am sure this is implementation dependent (try it on more variants - HP-UX, BSD ...)
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

How is it work the event handlers!?

I just have started studying perl and I can not figure out what is the exact strategy used in the following script to handle events. Precisely, what I do not understand is if the loop that is in charge to control the state of the socket, is managed at the system level (where the process will be... (2 Replies)
Discussion started by: flaviofachin
2 Replies

2. Programming

Signal function

Hello I want to know how can i use signal function in c for keyboard interrupt handling. what i exactly want is : my program is processing and if i press any key while processing , the program should call the interrupt and displays/prints that key and now goes back to processing. I added the... (5 Replies)
Discussion started by: Jahanzeb
5 Replies

3. Solaris

Exiting signal 6

Hello all, I have a problem when installing Solaris 10 on Enterprise 450. I booted from dvd, then the installation was started. The error appeared after determining the installation method, F2-Standard, F?-Flash...... The error was Exiting signal 6. Please, need help. Thank you (4 Replies)
Discussion started by: Hardono
4 Replies

4. Programming

Error: too many arguments to function 'sigwait'

#include <pthread.h> #include <signal.h> ... sigset_t mask; int err,signo; err=sigwait(&mask,&signo); switch(signo){ case SIGINT: ... } when I compile above code under solaris 10,it raise following error: error: too many arguments to function 'sigwait' I look up signal... (4 Replies)
Discussion started by: konvalo
4 Replies

5. Programming

Signal handling

I am trying to write a small program where I can send signals and then ask for an action to be triggered if that signal is received. For example, here is an example where I am trying to write a programme that will say you pressed ctrl*c when someone presses ctrl+c. My questions are what you would... (1 Reply)
Discussion started by: #moveon
1 Replies

6. Programming

Signal processing

We have written a deamon which have many threads. We are registering for the SIGTERM and trying to close main thread in this signal handling. Actually these are running on Mac OS X ( BSD unix). When we are unloading the deamon with command launchctl, it's sending SIGTERM signal to our process... (1 Reply)
Discussion started by: Akshay4u
1 Replies

7. Programming

RLIMIT_STACK signal's

I'am expecting a signal, but no signal is received when the stack-size reaches 10 bytes. Here in this code i'am setting rlim_cur=10bytes. To be more precise, when it reaches 10 bytes the process must receive a SIGSEGV signal? But i find no signal being received. Am i missing something in this... (0 Replies)
Discussion started by: prajwalps97
0 Replies

8. Programming

sigwait system call in UNIX signal

Hi Everybody, I have gone through man of sigwait and new to UNIX signals. Could anyone explain me about the following lines mentioned in sigwait man help ? "The selection of a signal in set is independent of the signal mask of the calling thread or LWP. This means a thread or LWP can ... (1 Reply)
Discussion started by: md7ahuja
1 Replies
Login or Register to Ask a Question