tags:

views:

57

answers:

1

Hi

How do I receive receive a signal sent with sigqueue in a c program (on linux)?

If just use kill to send a signal I just add a receiver with something like this

signal(SIGUSR1,  sigusr1);

that point to a simple function like this:

void sigusr1() 
{  
    signal(SIGUSR1,sigusr1);
    printf("SIGUSR1 ....\n");
}

But if I send a signal with sigqueue, how would I do then?

Thanks Johan


Add a sigaction:

struct sigaction action;

action.sa_flags = SA_SIGINFO; 
action.sa_sigaction = &sigusr2;

if (sigaction(SIGUSR2, &action, NULL) == -1) { 
    perror("sigusr: sigaction");
    _exit(1);
}

Where sigusr2 would look something like this:

void sigusr2(int signo, siginfo_t *info, void *extra) 
{
       void *ptr_val = info->si_value.sival_ptr;
       int int_val = info->si_value.sival_int;
       printf("Signal %d, value %d  \n", signo, int_val);
}

And just for ref a sigqueue example

sigval value;

for(int i=10;i<20;i++)
{
    value.sival_int = i;
    sigqueue(pid,SIGUSR2, value);
}
+1  A: 

Use sigaction.

Delan Azabani
Looks good, you don't happen to have a example as well?
Johan
Unfortunately as I don't have much experience in this area, I don't, but I'll look for one.
Delan Azabani
This may be what you want. http://www.helsinki.fi/atk/unix/dec_manuals/DOC_40D/APS33DTE/DOCU_006.HTM#realtime-handler-sec
Delan Azabani