how to blicked waiting for a signal in thread.

I have a situation where ihave to do some cleanup afeter receiving signal. I can not do that in signal handler. I tried using sigwait. but it(thread) is not becoming ready after receiving signal first time. if you send the signal again( second time) thread is becoming ready and doing the cleanup. Is there any way to become ready after catching the signal first time itself.

How do you send the signal. Signals by default will go to any thread ( you can predict which one). I think you need to use pthread_kill() to make sure it goes the exact thread.

i have only one thread waiting for signals

The main process does count as a thread.

I use slay “appname”.Then My thread should come out of the blocking state. and has to do some clenauo and exit. first time if use slay it is not happening. if use slay agin thread is coming out of blocking state.

The following program should work as you expect:

#include <signal.h>
#include <stdio.h>

int main(void)

int sig= 0;
sigset_t set;
sigemptyset( &set );
sigaddset( &set, SIGTERM );

sigwait ( &set, &sig );

printf("%d\n", sig );

return 0;    


Now if I were to add a thread to this program and wait for the signal in the thread but NOT in the main process, when slay appname is executed, there is NO telling to which thread the signal will go to. It might go to the thread were it will be process or it my go the the main process, to also be process, ignored, depending how signal handler and mask are setup.

I suggest you read the section “Signals and threads” in the manual. It will inform you that you need to mask the signal in the other “thread”.