zoukankan      html  css  js  c++  java
  • 信号总结(二)

    #include<signal.h>    sigsuspend(const sigset_t *mask ) ;

    NAME
           sigsuspend - wait for a signal

    SYNOPSIS
           #include <signal.h>

           int sigsuspend(const sigset_t *mask);

       Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

           sigsuspend(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE

    DESCRIPTION
           sigsuspend()  temporarily replaces the signal mask of the calling process with the mask given by mask and then

    suspends the
           process until delivery of a signal whose action is to invoke a signal handler or to terminate a process.

           If the signal terminates the process, then sigsuspend() does not return.   If  the  signal  is  caught,  then 

    sigsuspend()
           returns after the signal handler returns, and the signal mask is restored to the state before the call to sigsuspend().

           It  is  not  possible  to block SIGKILL or SIGSTOP; specifying these signals in mask, has no effect on the process's

    signal
           mask.

    RETURN VALUE
           sigsuspend() always returns -1, normally with the error EINTR.

    ERRORS
           EFAULT mask points to memory which is not a valid part of the process address space.

      EINTR  The call was interrupted by a signal.

    CONFORMING TO
    NOTES
           Normally, sigsuspend() is used in conjunction with sigprocmask(2) in order to prevent delivery of a signal during the 

    execution  of  a  critical code section.  The caller first blocks the signals with sigprocmask(2).  When the critical code

    has completed, the caller then waits for the signals by calling sigsuspend() with the signal mask that was returned by

    sigprocmask(2) (in the oldset argument).

    See sigsetops(3) for details on manipulating signal sets.

    上面说了这个不能阻塞SIGKILL,SIGSTOP。通常和sigprocmask联合使用,用来保护临界区代码中信号的传递。意思就是能保证这个信号处理函数正确的返回。

    这个函数的妙用书中使用例子来呈现的。

    第一个是用来保护一个全局变量。保证在改写此变量的时候程序不会中止,或者被其他信号中断。

    第二个是用来实现父子进程间的通信。实际上也是通过第一个来实现控制的。

  • 相关阅读:
    HDU5087——Revenge of LIS II(BestCoder Round #16)
    HDU5086——Revenge of Segment Tree(BestCoder Round #16)
    POJ3009——Curling 2.0(DFS)
    POJ2891——Strange Way to Express Integers(模线性方程组)
    算法总结之求解模线性方程组
    Linux运维学习笔记-网络技术知识体系总结
    Linux运维学习笔记-定时任务知识总结
    Linux运维学习笔记-文件权限知识总结
    Linux运维学习笔记-常用快捷键及vi、vim总结
    Linux运维学习笔记-角色知识总结
  • 原文地址:https://www.cnblogs.com/ppazhang/p/3637237.html
Copyright © 2011-2022 走看看