文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>小研究一下sigsuspend()函数

小研究一下sigsuspend()函数

时间:2006-11-10  来源:longtem

手册:
       #include <signal.h>

       int sigsuspend(const sigset_t *sigmask);

       The  sigsuspend()  function  shall replace the current signal mask of the calling thread with the set of
       signals pointed to by sigmask and then suspend the thread until delivery of a  signal  whose  action  is
       either to execute a signal-catching function or to terminate the process. This shall not cause any other
       signals that may have been pending on the process to become pending on the thread.

       If the action is to terminate the process then sigsuspend() shall never return. If the action is to exe-
       cute  a  signal-catching  function,  then  sigsuspend()  shall return after the signal-catching function
       returns, with the signal mask restored to the set that existed prior to the sigsuspend() call.

       It is not possible to block signals that cannot be ignored. This is enforced by the system without caus-
       ing an error to be indicated.

       也就是说,sigsuspend后,进程就挂在那里,等待着开放的信号的唤醒。系统在接受到信号后,马上就把现在的信号集还原为原来的,然后调用处理函数。实验用的源代码及其分析:

#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>

void wake()
{
   puts("INT CALLED"); //Tell the user that the handler has been invoked
   sleep(10);                  //used to prove that the sigset has been restored
   signal(SIGINT,SIG_DFL);//used to prove,a little later, that the SIGINT has been blocked
   return;//do nothing more, just return to wake the precess
}

int main()
{
        sigset_t        seta;

        //---init all data---
        sigfillset(&seta);
        signal(SIGINT,wake);
        sigprocmask(SIG_SETMASK,&seta,NULL);
        sigdelset(&seta,SIGINT);

        puts("All the thing has been done. I will sleep 10 for minutes. Just do what ever you want! Never send the 9th sig.");
        sleep(10);
        puts("I wake up now!");
    sleep(1);
        puts("I will sigsuspend! After this, the blocked signal will be released!");
        sigsuspend(&seta);

        puts("I have return from the handler. I will sleep for 10 minutes. You can press ctrl-c to send sigint");
        sleep(10);
        puts("Reaching the end!");
        return 0;
}
相关阅读 更多 +
排行榜 更多 +
锤击

锤击

休闲益智 下载
穿越时空的猫里奥

穿越时空的猫里奥

动作格斗 下载
麻匪动态壁纸

麻匪动态壁纸

主题美化 下载