• 信号总结(二)


    #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联合使用,用来保护临界区代码中信号的传递。意思就是能保证这个信号处理函数正确的返回。

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

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

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

  • 相关阅读:
    超强、超详细Redis数据库入门教程
    性能测试学习线路图(建议)
    性能测试分析软件汇总–开源、商业全部收集
    基于Locust、Tsung的百万并发秒杀压测案例[转]
    brew update失败提示:/System/Library/Frameworks/Ruby.framework/。。。解决方法
    XML特殊符号
    tsuang简易教程-MAC版
    【转】SQL Server获取日期或时间
    autoIT 传参数含引号
    Autoit 脚本以及 Java 调用
  • 原文地址:https://www.cnblogs.com/ppazhang/p/3637237.html
Copyright © 2020-2023  润新知