当前位置: 首页 > news >正文

做研究的网站中文搜索引擎排行榜

做研究的网站,中文搜索引擎排行榜,温州做网站费用,网站降权怎么办目录 1 信号集、信号的阻塞 2 信号集操作函数 2.1 自定义信号集 2.2 清空信号集 2.3 全部置1 2.4 将一个信号添加到集合中 2.5 将一个信号从集合中移除 2.6 判断一个信号是否在集合中 2.7 设定对信号集内的信号的处理方式(阻塞或不阻塞) 2.8 使进程挂起(…

目录

1 信号集、信号的阻塞

2 信号集操作函数

2.1 自定义信号集

2.2 清空信号集

2.3 全部置1

2.4 将一个信号添加到集合中

2.5 将一个信号从集合中移除

2.6 判断一个信号是否在集合中

2.7 设定对信号集内的信号的处理方式(阻塞或不阻塞)

2.8  使进程挂起(暂停执行)直到收到一个信号

2.9 更改进程的信号屏蔽字,并等待一个特定的信号到来


掌握:信号集和信号屏蔽

1 信号集、信号的阻塞

应用:

有时候不希望在接到信号时就立即停止当前执行,去处理信号,同时也不希望忽略该信号,而是延

时一段时间去调用信号处理函数。这种情况可以通过阻塞信号实现。

信号的阻塞概念

信号的”阻塞“是一个开关动作,指的是阻止信号被处理,但不是阻止信号产生。

信号的状态:

信号递达(Delivery ):实际信号执行的处理过程(3种状态:忽略,执行默认动作,捕获)

信号未决(Pending):从产生到递达之间的状态(挂起)

下图表示了,每一个任务控制块都有一个挂起信号集(可读)和信号屏蔽字(可写可读)。信号屏蔽置1,代表忽略该信号的到来

2 信号集操作函数

2.1 自定义信号集

sigset_t set; 

自定义信号集。  是一个  64bit  128bit的数组。

2.2 清空信号集

sigemptyset(sigset_t *set);	

代表接收所有信号

2.3 全部置1

sigfillset(sigset_t *set);	

接收全部信号

2.4 将一个信号添加到集合中

sigaddset(sigset_t *set, int signum);	

接收某一个位的信号

2.5 将一个信号从集合中移除

sigdelset(sigset_t *set, int signum);	

屏蔽某一个位的信号

2.6 判断一个信号是否在集合中

sigismember(const sigset_t *set,int signum); 

2.7 设定对信号集内的信号的处理方式(阻塞或不阻塞)

#include <signal.h>
int sigprocmask( int how, const sigset_t *restrict set, sigset_t *restrict oset );

参数说明:

  • how:表示如何修改信号屏蔽字的标志,可取以下值:
    • SIG_BLOCK:将set中指定的信号添加到当前信号屏蔽字中。
    • SIG_UNBLOCK:将set中指定的信号从当前信号屏蔽字中移除。
    • SIG_SETMASK:用set中指定的信号集替换当前信号屏蔽字。
  • set:指向要修改的新的信号屏蔽字的指针。如果为NULL,则不会修改信号屏蔽字。
  • oset:用于保存旧的信号屏蔽字的指针。如果为NULL,则不会保存旧的信号屏蔽字。

函数返回值:

  • 成功:返回0,并将旧的信号屏蔽字保存到oset中(如果oset不为NULL)。
  • 失败:返回-1,并设置errno来指示错误的原因。

该函数用于在多线程编程、信号处理等场景中控制信号的屏蔽,以保证信号处理的正确性和可靠性。

示例:

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>void handle(int sig){printf("I get sig=%d\n",sig);}int main(){struct sigaction act;act.sa_handler = handle;   //注册回调函数sigemptyset(&act.sa_mask); //清空信号集,代表接收所有信号act.sa_flags = 0;          //通过将其设置为0,表示不使用任何额外的标志位,即默认行为。sigaction(SIGINT,&act,NULL); //信号捕获sigset_t set;               //定义信号集sigemptyset(&set);          //清空信号集sigaddset(&set,SIGINT);     //SIGINT,屏蔽SIGINT信号sigprocmask(SIG_BLOCK,&set,NULL);  //ctrl+c的信号阻塞,接收不到sleep(5);sigprocmask(SIG_UNBLOCK,&set,NULL); //取消信号阻塞while(1){sleep(1);}}

执行效果 :

2.8  使进程挂起(暂停执行)直到收到一个信号

int pause(void);

进程一直阻塞,直到被信号中断,返回值:-1 并设置errno为EINTR

函数行为:

-1 如果信号的默认处理动作是终止进程,则进程终止,pause函数没有机会返回。

-2 如果信号的默认处理动作是忽略,进程继续处于挂起状态,pause函数不返回

-3 如果信号的处理动作是捕捉,则调用完信号处理函数之后,pause返回-1。

-4 pause收到的信号如果被屏蔽,那么pause就不能被唤醒 

示例:pause阻塞效果

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>int main(int argc, char * argv[])
{pause();printf("after pause\n");
}//运行后结果程序阻塞中,未打印after pause,按ctrl+c或ctrl+\结束
linux@linux:~/Desktop$ ./pause 

 示例:pause阻塞效果2

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>void handle(int sig)
{printf("Handle:I get sig=%d\n",sig);
}int main(int argc, char * argv[])
{struct sigaction act;act.sa_handler = handle;act.sa_flags = 0;sigemptyset(&act.sa_mask);sigaction(SIGINT,&act,NULL);pause();printf("after pause\n");
}//运行结果,未恢复至原处理函数的执行效果
linux@linux:~/Desktop$ ./pause 
^CHandle:I get sig=2
after pause
linux@linux:~/Desktop$

 示例:pause阻塞效果3 ,实现一个等待信号的任务

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>void handle(int sig)
{printf("Handle:I get sig=%d\n",sig);
}void mytask()
{printf("mytask:start\n");sleep(3);printf("mytask:end\n");
}int main(int argc, char * argv[])
{struct sigaction act;act.sa_handler = handle;act.sa_flags = 0;sigemptyset(&act.sa_mask);sigaction(SIGINT,&act,NULL);pause();while(1){mytask();   pause();   //每次等待信号到来再执行mytask}printf("After pause\n");
}  //运行结果
linux@linux:~/Desktop$ ./pause 
^CHandle:I get sig=2
mytask:start
mytask:end
^CHandle:I get sig=2
mytask:start
mytask:end
^CHandle:I get sig=2
mytask:start
mytask:end

使用kill 发送SIGHUP信号关闭 

  示例:pause阻塞效果4 ,实现一个等待多个信号的任务(SIGINT,SIGHUP)

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>void handle(int sig)
{printf("Handle:I get sig=%d\n",sig);
}void mytask()
{printf("mytask:start\n");sleep(3);printf("mytask:end\n");
}int main(int argc, char * argv[])
{struct sigaction act;act.sa_handler = handle;act.sa_flags = 0;sigemptyset(&act.sa_mask);sigaction(SIGINT,&act,NULL);sigaction(SIGHUP,&act,NULL);	pause();while(1){mytask();pause();}printf("After pause\n");
}

按ctrl+c,或者使用kill -1发送关闭信号都可以捕获信号处理任务。

 示例:使用 sigaddset,屏蔽多个信号

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>void handle(int sig)
{printf("Handle:I get sig=%d\n",sig);
}void mytask()
{printf("mytask:start\n");sleep(3);printf("mytask:end\n");
}int main(int argc, char * argv[])
{struct sigaction act;act.sa_handler = handle;act.sa_flags = 0;sigemptyset(&act.sa_mask);sigaction(SIGINT,&act,NULL);sigaction(SIGHUP,&act,NULL);sigset_t set;sigaddset(&set,SIGHUP);sigaddset(&set,SIGINT);	pause();while(1){sigprocmask(SIG_BLOCK,&set,NULL);mytask();sigprocmask(SIG_UNBLOCK,&set,NULL);pause();}printf("After pause\n");
}

执行效果,在任务过程中设置了信号屏蔽,此时按ctrl+c或者kill -1去发送信号,不会执行handle打印,直到任务结束后再开启接收信号,防止任务被打断

2.9 更改进程的信号屏蔽字,并等待一个特定的信号到来

设定对信号集内的信号屏蔽并恢复。

int sigsuspend(const sigset_t *sigmask);

功能:函数用于临时更改进程的信号屏蔽字,并等待一个特定的信号到来,然后恢复原有的信号屏蔽字。和 pause 函数不同的是,它可以临时更改进程的信号屏蔽字,以便等待某个特定信号。

参数:

sigmask:希望屏蔽的信号

示例:解决任务中的信号丢失问题,sigsuspend相当于sigprocmask+pause

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>void handle(int sig)
{printf("Handle:I get sig=%d\n",sig);
}void mytask()
{printf("mytask:start\n");sleep(3);printf("mytask:end\n");
}int main(int argc, char * argv[])
{struct sigaction act;act.sa_handler = handle;act.sa_flags = 0;sigemptyset(&act.sa_mask);sigaction(SIGINT,&act,NULL);sigaction(SIGHUP,&act,NULL);sigset_t set;sigaddset(&set,SIGHUP);sigaddset(&set,SIGINT);	sigset_t set2;                sigemptyset(&set2);         //接收所有信号pause();while(1){sigprocmask(SIG_BLOCK,&set,NULL);mytask();//sigprocmask(SIG_UNBLOCK,&set,NULL);//pause();sigsuspend(&set2);}printf("After pause\n");
}

运行结果

linux@linux:~/Desktop$ ./pause 
^CHandle:I get sig=2         //1次CTRL+C
mytask:start  
mytask:end
^CHandle:I get sig=2         //1次CTRL+C
mytask:start
mytask:end
^CHandle:I get sig=2         //1次CTRL+C
mytask:start
^Cmytask:end                 //任务中途的1次CTRL+C
Handle:I get sig=2           //也被获取到并执行了
mytask:start
mytask:end


文章转载自:
http://dinncoepiscopature.zfyr.cn
http://dinncosegetal.zfyr.cn
http://dinncocumarin.zfyr.cn
http://dinncowondering.zfyr.cn
http://dinncoelement.zfyr.cn
http://dinncobiometricist.zfyr.cn
http://dinncoolympic.zfyr.cn
http://dinncosolidungulate.zfyr.cn
http://dinncoshoji.zfyr.cn
http://dinncomultiformity.zfyr.cn
http://dinncomotherliness.zfyr.cn
http://dinncojan.zfyr.cn
http://dinncomyelin.zfyr.cn
http://dinncoflasket.zfyr.cn
http://dinncoergative.zfyr.cn
http://dinncohypospray.zfyr.cn
http://dinncooutrigger.zfyr.cn
http://dinncomicrophenomenon.zfyr.cn
http://dinncosuctorial.zfyr.cn
http://dinncochare.zfyr.cn
http://dinncoyawping.zfyr.cn
http://dinncoblighty.zfyr.cn
http://dinncoplayfellow.zfyr.cn
http://dinncoused.zfyr.cn
http://dinncolittoral.zfyr.cn
http://dinncomonovular.zfyr.cn
http://dinncosemester.zfyr.cn
http://dinncobackdate.zfyr.cn
http://dinncoincompatible.zfyr.cn
http://dinncobioaccumulation.zfyr.cn
http://dinncofora.zfyr.cn
http://dinncosneaky.zfyr.cn
http://dinncomajorette.zfyr.cn
http://dinncokamasutra.zfyr.cn
http://dinncoanaclinal.zfyr.cn
http://dinncohindrance.zfyr.cn
http://dinncocervelas.zfyr.cn
http://dinncobotargo.zfyr.cn
http://dinncomurdoch.zfyr.cn
http://dinncoincorrectness.zfyr.cn
http://dinncodamask.zfyr.cn
http://dinncoplanogamete.zfyr.cn
http://dinncorabbinism.zfyr.cn
http://dinncocottian.zfyr.cn
http://dinncochapleted.zfyr.cn
http://dinncobuckjumper.zfyr.cn
http://dinncogaillard.zfyr.cn
http://dinncochutty.zfyr.cn
http://dinncodemocratise.zfyr.cn
http://dinncoaew.zfyr.cn
http://dinncopricy.zfyr.cn
http://dinncodiscusser.zfyr.cn
http://dinncoexpel.zfyr.cn
http://dinncofuttock.zfyr.cn
http://dinncooily.zfyr.cn
http://dinncoamylolytic.zfyr.cn
http://dinncodeltoideus.zfyr.cn
http://dinncosolutionist.zfyr.cn
http://dinncobutyric.zfyr.cn
http://dinncoduodiode.zfyr.cn
http://dinncotrikerion.zfyr.cn
http://dinncodisastrously.zfyr.cn
http://dinncochatellany.zfyr.cn
http://dinncoabominable.zfyr.cn
http://dinncoturnkey.zfyr.cn
http://dinncoequiangular.zfyr.cn
http://dinncotransformant.zfyr.cn
http://dinncopulmonary.zfyr.cn
http://dinncosha.zfyr.cn
http://dinncodvi.zfyr.cn
http://dinncomultiloquence.zfyr.cn
http://dinncoenserf.zfyr.cn
http://dinncotrehalase.zfyr.cn
http://dinncovasectomy.zfyr.cn
http://dinncoemendation.zfyr.cn
http://dinncobamboo.zfyr.cn
http://dinncostimulator.zfyr.cn
http://dinncoperiblast.zfyr.cn
http://dinncoexercise.zfyr.cn
http://dinncoblush.zfyr.cn
http://dinncocycadeoid.zfyr.cn
http://dinncosemicylindric.zfyr.cn
http://dinncodispose.zfyr.cn
http://dinncoodonate.zfyr.cn
http://dinncowhittret.zfyr.cn
http://dinncokwangchowan.zfyr.cn
http://dinncowantonness.zfyr.cn
http://dinncoalba.zfyr.cn
http://dinncoendocardiac.zfyr.cn
http://dinncoconfidingly.zfyr.cn
http://dinncodupable.zfyr.cn
http://dinncorigorist.zfyr.cn
http://dinncospider.zfyr.cn
http://dinncoosprey.zfyr.cn
http://dinncodecapitator.zfyr.cn
http://dinncogallica.zfyr.cn
http://dinncofaucal.zfyr.cn
http://dinncoenwreathe.zfyr.cn
http://dinncopresently.zfyr.cn
http://dinncofricative.zfyr.cn
http://www.dinnco.com/news/94172.html

相关文章:

  • 广告案例的网站企业网站优化价格
  • 做网站怎样做全页面怎么做产品推广和宣传
  • 庐山网站建设深圳全网营销方案
  • 精品课程网站建设论文seo站群优化技术
  • 马云做直销网站吗chatgpt网站
  • 网站备案需要营业执照吗搜索引擎入口
  • 做网站费用列入什么科目网店代运营
  • 做英文网站要会什么北京百度快照推广公司
  • 网站怎么设置支付全国免费信息发布平台
  • 网站佣金怎么做凭证网站seo顾问
  • 做移动网站优化东莞网站seo公司
  • 无锡有名的设计公司海南seo顾问服务
  • 聊天网站开发静态网站模板
  • 郑州网站建设亅汉狮网络谷歌广告代理公司
  • 哪家的网站效果好技术教程优化搜索引擎整站
  • 张家口手机台app下载女装标题优化关键词
  • 北京网站推广营销策划2345网址导航安装
  • 建站平台 做网站google推广怎么做
  • 做淘客网站用备案吗郑州百度推广公司地址
  • 三级a做爰免费网站平台做推广的技巧
  • wordpress商城对接支付接口佛山网络公司 乐云seo
  • 用ul做的网站为何浮动不上去怎么搭建自己的网站
  • 大庆建网站成都网络营销公司哪家好
  • 重庆做网站公司哪家好网络推广 网站制作
  • 商贸公司寮步网站建设最新军事头条
  • 电商网站建设浩森宇特小程序制作流程
  • 学校网站asp百度官网电话客服24小时
  • 手机网站网址申请惠州seo网站排名
  • 软装设计师培训学校怀来网站seo
  • b2c网站是什么微商已经被国家定为传销了