sigwait

sigwait是一個函式,它提供了一種等待信號的到來,以串列的方式從信號佇列中取出信號進行處理的機制。

基本介紹

  • 外文名:sigwait
  • 提供了:一種等待信號的到來
  • 方式:串列的方式
  • 特點:從信號佇列中取出信號進行處理
函式名:,描述,返回值,

函式名:

sigwait - wait for a signal
摘要
#include <signal.h>int sigwait(const sigset_t *set, int *sig);
Feature Test Macro Requirements for glibc (seefeature_test_macros(7)):
sigwait(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE

描述

Thesigwait() function suspends execution of the calling thread until the delivery of one of the signals specified in the signal setset. The function accepts the signal (removes it from the pending list of signals), and returns the signal number insig.
The operation ofsigwait() is the same assigwaitinfo(), except that:
* sigwait() only returns the signal number, rather than asiginfo_tstructure describing the signal. * The return values of the two functions are different.
sigwait() 提供了一種等待信號的到來,以串列的方式從信號佇列中取出信號進行處理的機制。sigwait()只等待函式參數中指定的信號集,即如果新產生的信號不在指定的信號集內,則 sigwait()繼續等待。對於一個穩定可靠的程式,我們一般會有一些疑問:
  • 不要線上程的信號掩碼中阻塞不能被忽略處理的兩個信號 SIGSTOP 和 SIGKILL。
  • 不要線上程的信號掩碼中阻塞 SIGFPE、SIGILL、SIGSEGV、SIGBUS。
  • 確保 sigwait() 等待的信號集已經被進程中所有的執行緒阻塞。
  • 在主執行緒或其它工作執行緒產生信號時,必須調用 kill() 將信號發給整個進程,而不能使用 pthread_kill() 傳送某個特定的工作執行緒,否則信號處理執行緒無法接收到此信號。
  • 因為 sigwait()使用了串列的方式處理信號的到來,為避免信號的處理存在滯後,或是非實時信號被丟失的情況,處理每個信號的代碼應儘量簡潔、快速,避免調用會產生阻塞的庫函式。

返回值

On success,sigwait() returns 0. On error, it returns a positive error number.

相關詞條

熱門詞條

聯絡我們