f



signal delivery in HP-UX 11.11

Hi,

I am Ravi Nandibhatla from India.

I am trying to send a SIGTSTP signal to the process. But this is
always getting handled by the thread instead of the process as a
whole. The same program when tried on Solaris machine (with minor
changes in functions), I could get the program suspended.

Please let me know 
1) why is this difference between HP-UX & Solaris ?
2) Which one of HP-UX & Solaris, is fully POSIX compliant while
talking about POSIX threads ?

Below is the sample program I wrote.

/* ============== cut here ===================== */
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

void* signal_handler(void *);
sigset_t set;

int main (int argc, char* argv[]) {
        pthread_t tid;
        int sig;
        int ret;

        sigemptyset(&set);
        sigaddset(&set,SIGTSTP);
        sigprocmask(SIG_BLOCK,&set,NULL);

        ret = pthread_create(&tid, NULL, signal_handler, NULL);
        sched_yield();

        printf("thread created...\n");

        pthread_exit(0);
        return(0);
}

void *signal_handler(void *arg) {

        int sig;
        printf("\nIn the thread.......\n");
        sigwait(&set,&sig);
        printf("signal handler started...\n");
}
/* ============== cut here ===================== */

I have compiled the the above program on HP-UX 11.11 as:

cc -g -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT filename.c -lpthread

and when I run it, the output is:
------------------------------
In the thread.......
thread created...
                           <<< when I press Ctrl+Z, the program comes
out with
signal handler started...
===========================================

Thanks in advance,
Ravi Nandibhatla.
0
nandibhatla
3/4/2004 12:54:33 PM
comp.sys.hp.hpux 4408 articles. 1 followers. dewi.bening (7) is leader. Post Follow

1 Replies
589 Views

Similar Articles

[PageSpeed] 23

Ravi Nandibhatla <nandibhatla@hotmail.com> wrote:

|I am trying to send a SIGTSTP signal to the process. But this is
|always getting handled by the thread instead of the process as a
|whole. The same program when tried on Solaris machine (with minor
|changes in functions), I could get the program suspended.

|Please let me know 
|1) why is this difference between HP-UX & Solaris ?
|2) Which one of HP-UX & Solaris, is fully POSIX compliant while
|talking about POSIX threads ?

  I don't see any problem with the behavior on HP-UX.  Your
process has two threads.  The main thread starts the second thread,
prints a line, and then exits.  The second thread is blocked
on sigwait for SIGTSTP.  When you press Ctrl+Z the second thread
catches a SIGTSTP, prints a line, and returns.  That exits from the
remaining thread and ends the program.

  I don't see any reason the program should become suspended.
Even if the main thread were lingering after printing that line,
it was already blocking SIGTSTP.

  You comment about a SIGTSTP being "handled by the thread" seems to
reflect a misunderstanding about threads and signal handling.  Only one
thread will handle any one signal.  In the case of a synchronous signal
like a SIGBUS from a memory access the signal will be taken by the
thread that caused it.  In the case of an asyncronous signal such as
terminal SIGTSTP or a signal from a kill(), the signal will be delivered
to the process.  It will be handled by one of the threads in the
process.  If multiple threads have not blocked the signal then it will
be delivered to one of those threads in an implementation dependent
manner.  If only one thread has the signal unblocked it will go to that
thread.

   Your sample program doesn't really show that a signal is handled by
only one thread.  In you test there is only one thread left.  It is in
sigwait with the signal unblocked.  It gets the signal and wakes from
sigwait.

  This kind of signal masking and handling are discussed in "man pthread".

-- 
Mike Stroyan, mike.stroyan@hp.com
0
Mike
3/6/2004 12:11:43 AM
Reply: