Sending a signal to a thread in Pthread

Source: Internet
Author: User
Tags signal handler

Pthread_killGrammar
tidsig);
sigtidret;ret = Pthread_kill ( tid sig );

pthread_kill()Sends the signal SIG to the thread specified by the tid . The thread specified by the tid must be in the same process as the calling thread. The sig parameter must come from the list provided by signal (5).

sends a SIG signal to a thread of the specified ID if the thread code does not handle it, the entire process is affected by the default behavior of the signal, that is, if you send a sigquit to a thread, but the thread does not implement the signal handler, the entire process exits.

Pthread_kill (ThreadID, SIGKILL), too, kills the whole process.
If you want to get the right behavior, you need to implement signal (Sigkill,sig_handler) within the thread.

So, if the int sig parameter is not 0, it must be clear exactly what to do, and must implement the signal processing function of the thread, otherwise, it will affect the entire process.

OK, if the int sig is 0, this is a reserved signal and a function is used to determine if the thread is still alive (the error check is performed, but the signal is not actually sent.) This error check can be used to check the validity of the tid . )。

Pthread_killreturn value

pthread_kill()Returns zero after a successful completion. Any other return value indicates an error occurred. If any of the following conditions occur, the pthread_kill() corresponding value will fail and be returned.

EINVAL

Describe:

sigis a semaphore that is not valid.

Esrch

Describe:

Cannot be found in the current process tid .

Sending a signal to a thread in Pthread

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.