簡體   English   中英

sigwait的怪異行為

[英]Weird behaviour of sigwait

我正在使用sigwait來阻止線程發出某些信號。 這些信號已添加到信號組中。 按照文檔sigwait的AS應該只等待作為參數中的set傳遞給它的信號,而不應該更改該線程的信號掩碼。但是由於某些原因,我不知道,它正在更改信號掩碼的線程。 它阻止信號以外的所有信號。 我不希望這種情況發生。 有人可以幫我嗎? 提前感謝

代碼段:

sigset_t sigs;
int sig_recvd;
sigset_t old_mask;
sigemptyset(&sigs);
sigaddset(&sigs, SIGUSR1);
sigaddset(&sigs, SIGTERM);
sigaddset(&sigs, SIGHUP);
sigaddset(&sigs, SIGINT);
sigaddset(&sigs, SIGPIPE);
sigaddset(&sigs, SIGCHLD);

sigprocmask(SIG_BLOCK, &sigs, &old_mask);

do
{

    sigwait(&sigs, &sig_recvd);
    //Switch for some signal handling

} while(1);

sigwait之前的Sigblk: 0000000080014203
sigwait期間的fffffffefffabcfcfffffffefffabcfc


我不知道sigwait函數有什么問題,但是當我對sigwaitinfo做同樣的事情時,事情就解決了。 無法弄清楚后來的工作是什么,但是現在我的問題解決了。 但我想知道兩者的實施是否有差異

我不太確定您的問題是什么,如果您的問題是“為什么sigwait 執行過程中而不是執行之后更改sigmast”,那么確實是這樣,sigwait將在執行時解鎖信號,否則如何期望信號到來嗎? 這是摘自APUE: If one of the signals specified in the set is pending at the time sigwait is called, then sigwait will return without blocking. Before returning, sigwait removes the signal from the set of signals pending for the process. To avoid erroneous behavior, a thread must block the signals it is waiting for before calling sigwait. The sigwait function will atomically unblock the signals and wait until one is delivered. Before returning, sigwait will restore the thread's signal mask. If the signals are not blocked at the time that sigwait is called, then a timing window is opened up where one of the signals can be delivered to the thread before it completes its call to sigwait If one of the signals specified in the set is pending at the time sigwait is called, then sigwait will return without blocking. Before returning, sigwait removes the signal from the set of signals pending for the process. To avoid erroneous behavior, a thread must block the signals it is waiting for before calling sigwait. The sigwait function will atomically unblock the signals and wait until one is delivered. Before returning, sigwait will restore the thread's signal mask. If the signals are not blocked at the time that sigwait is called, then a timing window is opened up where one of the signals can be delivered to the thread before it completes its call to sigwait If one of the signals specified in the set is pending at the time sigwait is called, then sigwait will return without blocking. Before returning, sigwait removes the signal from the set of signals pending for the process. To avoid erroneous behavior, a thread must block the signals it is waiting for before calling sigwait. The sigwait function will atomically unblock the signals and wait until one is delivered. Before returning, sigwait will restore the thread's signal mask. If the signals are not blocked at the time that sigwait is called, then a timing window is opened up where one of the signals can be delivered to the thread before it completes its call to sigwait

為什么不使用pthread_sigmask()而不是sigprocmask()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM