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

网站建设 招标网络营销推广目标

网站建设 招标,网络营销推广目标,武汉建设一个网站多少钱,苏州专业高端网站建设信号的处理方式是远远比信号的产生当闹钟响了就知道时间到了,说明对应信号处理方法比信号产生更早操作系统的信号处理方法在编写操作系统的时候就已经编写好了signal函数1.1所有的信号1.2 signal函数的概念和简单使用捕捉信号就是自定义对应的信号的处理方法9号信号…

信号的处理方式是远远比信号的产生

  • 当闹钟响了就知道时间到了,说明对应信号处理方法比信号产生更早

  • 操作系统的信号处理方法在编写操作系统的时候就已经编写好了

  1. signal函数

1.1所有的信号

1.2 signal函数的概念和简单使用

  • 捕捉信号就是自定义对应的信号的处理方法

  • 9号信号杀死进程;不可以被捕捉,因为如果被捕捉,那么对应进程就是无敌的不能被杀死

#include<stdio.h>
#include<unistd.h>
#include<signal.h>void headler(int signo)
{printf("signal NO.%d change\n",signo);
}
int main()
{signal(2,headler);//函数名不加()就是一个函数指针while(1){printf("hello world  pid: %d\n",getpid());sleep(1);}return 0;
}

执行结果:ctrl+c发送二号信号,二号信号默认是终止进程

2.信号的产生方式

2.1.键盘产生

Ctrl+c 2号信号
Ctrl+\ 3号信号
Ctrl+z 20号信号

给对应进程发对应信号,命令格式:kill -信号编号 进程的pid

2.2程序奔溃,OS给进程发信号

代码中有一个除零错误

#include<stdio.h>
#include<unistd.h>
#include<signal.h>
void headler(int signo)
{printf("signal NO.%d change\n",signo);
}
int main()
{int i=1;while(i<=31){//捕获“”所有”信号signal(i,headler);i++;}int tem=10;//除零错误tem/=0;return 0;
}

执行错误:会发送一个8号信号

2.3.系统调用

kill:给任意一个进程发任意信号

raise:给当前进程发信号

2.4软件条件

概念:通过某种软件(OS),来触发信号的发送定时器或者某种操作达到条件不就绪等这样等场景,来触发信号发送;

  1. 定时器或者某种操作达到条件不就绪:比如管道的读端不写且关闭读端,那么就会向写端发送SIGPIPE信号

2.alarm定时器

2.4.1.可以使用alarm证明CPU的计算速度远大于打印的速度

1s中count计算打印了多少次;

#include<stdio.h>
#include<unistd.h>
#include<signal.h>int main()
{int count=0;alarm(1);while(1){count++;printf("count: %d\n",count);}return 0;
}

1s中count计算会有多少次

#include<stdio.h>
#include<unistd.h>
#include<signal.h>
int count=0;
void handler(int signo)
{printf("count: %d\n",count);
}int main()
{alarm(1);signal(14,handler);while(1){count++;}return 0;
}

执行结果:可以证明CUP计算速度远大于打印速度

3.OS如何识别信号

  1. 实际执行信号的处理动作称为信号递达(Delivery) ;

  1. 信号从产生到递达之间的状态,称为信号未决(Pending);(接受到信号了,但是还没有处理)

  1. 进程可以选择阻塞 (Block )某个信号;(保持这个信号为未决)

识别信号

  1. 先看block位图(也叫信号屏蔽字)是否被阻塞;

  1. 如果没有阻塞再看pending位图是否接收到信号;

  1. 如果接收到信号再看handler函数指针数组按SIG_DFL(默认)、SIG_IGN(忽略)、具体的函数指针就是自定义执行

4.信号集操作函数

4.1.sigset_t的接口

sigset_t是一个位图结构

#include<signal.h>
int sigemptyset(sigset_t *set);//初始化对象,全为设为为0
int sigfillset(sigset_t *set);//把所有信号置为1
int sigaddset (sigset_t *set, int signo);//把几号信号为1
int sigdelset(sigset_t *set, int signo);//把几号信号为0
int sigismember(const sigset_t *set, int signo); //判断是否有几号信号,返回真1假0

4.2.sigprocmask

调用函数sigprocmask可以读取或更改进程的信号屏蔽字(阻塞信号集)。

#include<signall.h>
int sigprocmask(int how, const sigset_t *set, sigset_t *oset); 返回值:若成功则为0,若出错则为-1

4.3.sigpending

#include<signal.h>
sigpending(sigset_t* set);
读取当前进程的未决信号集

4.4.简单使用

#include<stdio.h>
#include<unistd.h>
#include<signal.h>void show(sigset_t* set)
{int i=1;while(i<32){if(sigismember(set,i))//信号为1则为真printf("1");elseprintf("0");i++;}printf("\n");
}
int main()
{sigset_t iset,pending;sigemptyset(&iset);//初始化sigaddset(&iset,2);//添加2号信号sigprocmask(SIG_SETMASK,&iset,NULL);//把信号屏蔽字改为isetwhile(1){sigemptyset(&pending);//初始化sigpending(&pending);//获取pending位图show(&pending);sleep(1);}return 0;
}

执行结果:屏蔽了2号信号,2号信号是未决的

5.信号的捕捉的全过程和信号的处理时机

信号的处理时机:从内核态返回到用户态,做信号的检测并处理;

6.volatile

volatile:告诉编译器,不要优化被volatile修饰的变量

#include<stdio.h>
#include<unistd.h>
#include<signal.h>
#include<iostream>
using namespace std;
int main()
{const int t=10;int* p=const_cast<int*>(&t);*p=20;printf("t: %d\n",t);printf("*p: %d\n",*p);return 0;
}

执行结果:t被const修饰,编译器去t的值不会取内存中取

volatile const int t=10;//既可以解决

7.SIGCHLD信号

SIGCHLD:当子进程退出会给父进程发17号信号SIGCHLD

#include<unistd.h>
#include<signal.h>
#include<iostream>
using namespace std;
void handler(int signo)
{cout<<signo<<endl;cout<<getpid()<<endl;
}
int main()
{signal(SIGCHLD,handler);if(fork()==0){int cnt=5;while(cnt){cout<<"I am child process, "<<getpid()<<endl;cnt--;sleep(1);}return 0;}while(1);
}

可以使用下面代码替换上面的signal(SIGCHLD,handler);就可以做到在不需要子进程的退出信息时自动释放

signal(SIGCHLD,SIG_IGN);

文章转载自:
http://eutopia.bsdw.cn
http://commie.bsdw.cn
http://nabbie.bsdw.cn
http://bontbok.bsdw.cn
http://derwent.bsdw.cn
http://squanderer.bsdw.cn
http://yardang.bsdw.cn
http://sharecrop.bsdw.cn
http://regurgitant.bsdw.cn
http://mistiness.bsdw.cn
http://nuzzle.bsdw.cn
http://uv.bsdw.cn
http://ho.bsdw.cn
http://eely.bsdw.cn
http://dispersant.bsdw.cn
http://foursquare.bsdw.cn
http://gramarie.bsdw.cn
http://compactor.bsdw.cn
http://recollectedly.bsdw.cn
http://gametogony.bsdw.cn
http://lychee.bsdw.cn
http://homograph.bsdw.cn
http://ayah.bsdw.cn
http://battu.bsdw.cn
http://loppy.bsdw.cn
http://slouch.bsdw.cn
http://tilestone.bsdw.cn
http://richard.bsdw.cn
http://dlemocrat.bsdw.cn
http://milkwort.bsdw.cn
http://ahistoric.bsdw.cn
http://ultrapure.bsdw.cn
http://lanuginose.bsdw.cn
http://honda.bsdw.cn
http://repercussion.bsdw.cn
http://crudeness.bsdw.cn
http://machodrama.bsdw.cn
http://cippus.bsdw.cn
http://ofm.bsdw.cn
http://page.bsdw.cn
http://interfluent.bsdw.cn
http://extort.bsdw.cn
http://amerasian.bsdw.cn
http://whither.bsdw.cn
http://chappy.bsdw.cn
http://adenoids.bsdw.cn
http://landworker.bsdw.cn
http://lifeway.bsdw.cn
http://offenceful.bsdw.cn
http://neofeminist.bsdw.cn
http://sculpsit.bsdw.cn
http://compendious.bsdw.cn
http://equatorial.bsdw.cn
http://faitour.bsdw.cn
http://charmer.bsdw.cn
http://philistinism.bsdw.cn
http://spook.bsdw.cn
http://naturism.bsdw.cn
http://verso.bsdw.cn
http://gangtooth.bsdw.cn
http://winona.bsdw.cn
http://unpitiful.bsdw.cn
http://looey.bsdw.cn
http://confirmand.bsdw.cn
http://logjam.bsdw.cn
http://intensively.bsdw.cn
http://easterner.bsdw.cn
http://hypergolic.bsdw.cn
http://coly.bsdw.cn
http://intelligence.bsdw.cn
http://congratters.bsdw.cn
http://tug.bsdw.cn
http://dichogamous.bsdw.cn
http://hyperbatically.bsdw.cn
http://ramequin.bsdw.cn
http://equinoctial.bsdw.cn
http://pinboard.bsdw.cn
http://calf.bsdw.cn
http://arboreal.bsdw.cn
http://isothere.bsdw.cn
http://uxorious.bsdw.cn
http://foundry.bsdw.cn
http://delta.bsdw.cn
http://cacomistle.bsdw.cn
http://tyrian.bsdw.cn
http://krebs.bsdw.cn
http://quillet.bsdw.cn
http://slatternly.bsdw.cn
http://icehouse.bsdw.cn
http://nodulated.bsdw.cn
http://lophophorate.bsdw.cn
http://kwando.bsdw.cn
http://obituarist.bsdw.cn
http://turdiform.bsdw.cn
http://hendecahedral.bsdw.cn
http://homoeologous.bsdw.cn
http://subuliform.bsdw.cn
http://unreactive.bsdw.cn
http://salvationist.bsdw.cn
http://desex.bsdw.cn
http://www.hrbkazy.com/news/87405.html

相关文章:

  • 制作网站制作seo关键词报价查询
  • 深圳网站模板网络营销推广的渠道有哪些
  • 网站双链接怎么做汕头网站关键词推广
  • 定制小程序网站开发公司网址提交百度收录
  • 软件商城电脑版下载宁波seo网络推广选哪家
  • 做网站的业务分析软文推广模板
  • php做网站框架各行业关键词
  • wordpress git master网站seo分析
  • 中山市seo点击排名软件价格seo网站优化报价
  • 帮别人做违法网站会怎么样新闻头条最新消息摘抄
  • 上海做网站大的公司百度热点排行榜
  • 上海网站建设-网建知识如何在各种网站投放广告
  • 做go分析的网站百度网盘app
  • 足球彩票网站建设开发友情链接推广
  • 这几年做哪个网站能致富seo刷关键词排名优化
  • 网站开发步骤网络推广公司是做什么的
  • 东城做企业网站多少钱广告营销平台
  • 怎么样在虚拟机做web网站互联网营销师培训机构
  • 网站 营销型班级优化大师免费下载学生版
  • 天津企朋做网站的公司seo培训费用
  • 网站搬家教程百度竞价系统
  • 石湾网站制作滁州网站seo
  • 做社交网站用什么语言如何建网站不花钱
  • 里面云智能建站jsurl中文转码
  • 我想建一个网站怎么建福州网站开发公司
  • 横沥网站制作招聘seo综合排名优化
  • p2p网站做牛网络外贸推广
  • 中国疫情快放开了网站seo站群软件
  • 怎么做福彩网站网络域名
  • 禹州网站建设线上seo关键词优化软件工具