• 信号总结(二)


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

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

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

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

  • 相关阅读:
    VIM 编辑器命令
    Ubuntu LAMP 便捷配置
    Linux基础命令
    Sql sever 定时任务设置
    C#自动发送邮件
    序列化与反序列化
    字符串.特殊引用类型
    抽象方法、接口
    函数的返回值
    线程
  • 原文地址:https://www.cnblogs.com/ppazhang/p/3637237.html
Copyright © 2020-2023  润新知