Multithreaded Programming Guide

Sending a Signal to a Thread

Use pthread_kill(3C) to send a signal to a thread.

pthread_kill Syntax

int  pthread_kill(pthread_t tid, int sig);
#include <pthread.h>
#include <signal.h>

int sig;
pthread_t tid;
int ret;

ret = pthread_kill(tid, 

pthread_kill() sends the signal sig to the thread specified by tid. tid must be a thread within the same process as the calling thread. Thesig argument must be from the list that is given in signal.h(3HEAD).

When sig is zero, error checking is performed but no signal is actually sent. This error checking can be used to check the validity of tid.

pthread_kill Return Values

pthread_kill() returns zero after completing successfully. Any other return value indicates that an error occurred. When either of the following conditions occurs, pthread_kill() fails and returns the corresponding value.



sig is not a valid signal number.



tid cannot be found in the current process.