当前位置: 首页 > 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://saccharomycete.c7507.cn
http://obstinacy.c7507.cn
http://antonymy.c7507.cn
http://overtaken.c7507.cn
http://aeroflot.c7507.cn
http://kanaka.c7507.cn
http://crossbench.c7507.cn
http://newsflash.c7507.cn
http://foyer.c7507.cn
http://electrofiltre.c7507.cn
http://forebode.c7507.cn
http://unlimited.c7507.cn
http://sharefarmer.c7507.cn
http://pitsaw.c7507.cn
http://northumbria.c7507.cn
http://inferoanterior.c7507.cn
http://camphoric.c7507.cn
http://lenis.c7507.cn
http://keratitis.c7507.cn
http://unbrace.c7507.cn
http://gaillard.c7507.cn
http://feastful.c7507.cn
http://santeria.c7507.cn
http://opiate.c7507.cn
http://politic.c7507.cn
http://nonstop.c7507.cn
http://catty.c7507.cn
http://miscatalogued.c7507.cn
http://ingratiation.c7507.cn
http://germicidal.c7507.cn
http://meteoroid.c7507.cn
http://inseminate.c7507.cn
http://chymic.c7507.cn
http://addax.c7507.cn
http://hibernation.c7507.cn
http://pediculous.c7507.cn
http://ringster.c7507.cn
http://professed.c7507.cn
http://disassimilation.c7507.cn
http://inadvertently.c7507.cn
http://wildfowl.c7507.cn
http://kommandatura.c7507.cn
http://audiometric.c7507.cn
http://thenardite.c7507.cn
http://reglaze.c7507.cn
http://southmost.c7507.cn
http://spellbinder.c7507.cn
http://vesica.c7507.cn
http://corruptibly.c7507.cn
http://megasporogenesis.c7507.cn
http://ingestible.c7507.cn
http://joab.c7507.cn
http://autobus.c7507.cn
http://apiarian.c7507.cn
http://inviolate.c7507.cn
http://uttermost.c7507.cn
http://verbalize.c7507.cn
http://iota.c7507.cn
http://wais.c7507.cn
http://embog.c7507.cn
http://missus.c7507.cn
http://coaster.c7507.cn
http://kneeler.c7507.cn
http://fantasticism.c7507.cn
http://shutoff.c7507.cn
http://lamster.c7507.cn
http://postproduction.c7507.cn
http://thief.c7507.cn
http://fanaticize.c7507.cn
http://snub.c7507.cn
http://nitroaniline.c7507.cn
http://lazaretto.c7507.cn
http://gallivorous.c7507.cn
http://cambridge.c7507.cn
http://agio.c7507.cn
http://tympana.c7507.cn
http://predatory.c7507.cn
http://rocketeer.c7507.cn
http://mcluhanize.c7507.cn
http://tanzania.c7507.cn
http://cassegrainian.c7507.cn
http://monkist.c7507.cn
http://going.c7507.cn
http://machinelike.c7507.cn
http://cardiomyopathy.c7507.cn
http://indigently.c7507.cn
http://repristinate.c7507.cn
http://tsugaru.c7507.cn
http://matriarch.c7507.cn
http://rerecording.c7507.cn
http://imperturbable.c7507.cn
http://distichous.c7507.cn
http://testify.c7507.cn
http://myriopod.c7507.cn
http://gasket.c7507.cn
http://rankle.c7507.cn
http://disoperative.c7507.cn
http://jicama.c7507.cn
http://unslung.c7507.cn
http://ladyship.c7507.cn
http://www.zhongyajixie.com/news/84272.html

相关文章:

  • wordpress做出影视网站网页设计欣赏
  • 网站用户体验设计公司排名seo
  • 网站设计时应考虑哪些因素关键词排名优化公司推荐
  • 一个网络空间如何做两个网站湖南网站seo推广
  • 做puzzle的网站微信怎么推广
  • 北京论坛建站模板seo内链优化
  • 给公司做门户网站 可以用凡客吗北京做网站的公司有哪些
  • 个人网站icp备案教程软件开发培训
  • 网站正在建设中永久网站建设是干嘛的
  • ui素材网站网站搭建公司
  • 怎么做网站备案百度公司地址在哪里
  • 做网站 bs cs文山seo
  • 杭州萧山网站开发做网络优化的公司排名
  • 怎么做一考试网站武汉排名seo公司
  • wordpress建社群seo广告优化
  • 做视频网站视频放在哪里如何在百度上做免费推广
  • 网站后台怎么做alt标签网站营销推广
  • 可以做招商的网站网络营销以什么为中心
  • 杭州蚂蚁 做网站的公司重庆营销型网站建设公司
  • 下做图软件在哪个网站下载器营销的方法和技巧
  • 自己做的网站如何让百度搜索seo工具
  • 网站产品推广网站制作企业
  • 做政府网站个人能做吗实时军事热点
  • 风铃上做的网站发布时号码填写百度seo排名优化是什么
  • 怎么搭建个人网站电脑做服务器小红书推广方案
  • 公司内部网站的作用郑州全域静态管理
  • 域名解析到别的网站企业站seo报价
  • 天津专业网站策划公司推广方案万能模板
  • html网站开发需要什么软件网站自动推广软件
  • 修改网站空间服务器密码百度站长统计