精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。需要全文内容也请联系孙老师。
This function is much cleaner and avoids races and errors !!!! 这个函数是更简洁的,避免竞争和错误! ! ! !
1. First block all signals 首选阻塞所有信号
2. Put the signals you want to wait for in sigset_t 把信号放在你想要等待sigset_t中
3. Call sigwait 调用sigwait
4. sigwaitblocks the process until at least one of these signals is pending. 调用sigwait块处理的过程,直到在这些信号中至少有一个是待定的。
5. It removes one of the pending signals and gives you the corresponding signal number in the second parameter..删除一个等待信号,给你在第二个参数对应的信号数量. .
6. Do what you want: no signal handler needed. 做你想做的事情:不需要信号处理器。
7. It returns 0 on success and -1 on error with errnoset.它在成功时,返回0,错误时,返回-1
#include <signal.h>
intsigwait(constsigset_t*restrict sigmask, int*restrict signo);
#include <signal.h>Example: Thread kills itself and the process it is in because SIGKILL cannot be caught, blocked, or ignored. 例子:线程杀死自己和它所在的进程,因为SIGKILL不能被捕获阻塞或忽略。
#include <pthread.h>
intpthread_kill(pthread_tthread, intsig);
If successful pthread_killreturns 0.
If (pthread_kill(pthread_self(), SIGKILL))
fprintf(stderr, “failed to commit suicide”\n”);
#include <pthread.h>If ‘how’is SIG_SETMASK, then thread’s signal mask is replaced by ‘set’如果'how'是SIG_SETMASK,那么线程的信号掩码被"set"替换
#include <signal.h>
intpthread_sigmask(inthow,
const sigset_t*restrict set,
sigset_t*restrict pset);