Home > OS >  Why are SIGSTOP/SIGCONT sent to all threads?
Why are SIGSTOP/SIGCONT sent to all threads?

Time:07-18

I have a process in Linux that has two POSIX threads running this function:

void *
threadFunc(void *args)
{
    (void)args;
    long id = pthread_self();

    while (1) {
        printf("Hello from %li\n", id);
        sleep(1);
    }

    return NULL;
}

I send the process a SIGSTOP. Both threads stop printing to the screen. I send a SIGCONT and both threads resume their printing.

Based on my understanding of how multithreaded processes handle signals, I would have thought that only thread would have received the signal. Why is it that both threads are stopped?

CodePudding user response:

SIGKILL and SIGSTOP are special in that they can't be caught, blocked, or ignored (see signal(7) man page for details), and the behavior of SIGSTOP is to stop the process, not a single thread (so it technically doesn't matter which of your threads receives the signal, the whole process will still stop).

  • Related