20 Alarms, sigaction(), and Reentrant System Calls
1 Alarm Signals and SIGALRM
1.1 Setting an alarm
unsigned int alarm(unsigned int seconds);
- 过n秒后向进程发送
SIGALARM
信号 SIGALARM
信号默认动作是terminate
#include <stdio.h>
#include <stdlib.h>#include <unistd.h>
#include <signal.h>
#include <sys/signal.h>void alarm_handler(int signum){printf("Buzz Buzz Buzz\n");
}int main(){//set up alarm handlersignal(SIGALRM, alarm_handler);//schedule alarm for 1 secondalarm(1);//do not proceed until signal is handledpause();}
1.2 Recurring Alarms
/* buzz_buzz.c*/void alarm_handler(int signum){printf("Buzz Buzz Buzz\n");//set a new alarm for 1 secondalarm(1);}int main(){//set up alarm handlersignal(SIGALRM, alarm_handler);//schedule the first alarmalarm(1);//pause in a loopwhile(1){pause();}}
1.3 Resetting Alarms
void sigint_handler(int signum){printf("Snoozing!\n");//schedule next alarm for 5 secondsalarm(5);
}void alarm_handler(int signum){printf("Buzz Buzz Buzz\n");//set a new alarm for 1 secondalarm(1);
}int main(){//set up alarm handlersignal(SIGALRM, alarm_handler);//set up signint handlersignal(SIGINT, sigint_handler);//schedule the first alarmalarm(1);//pause in a loopwhile(1){pause();}}
2 sigaction() and Reentrant Functions
2.1 sigaction()
1.int sigaction(int signum, const struct sigaction *act,struct sigaction *oldact);
2.
struct sigaction {void (*sa_handler)(int);void (*sa_sigaction)(int, siginfo_t *, void *);sigset_t sa_mask;int sa_flags;
};
void handler(int signum){printf("Hello World!\n");
}int main(){//declare a struct sigactionstruct sigaction action;//set the handleraction.sa_handler = handler;//call sigaction with the action structuresigaction(SIGALRM, &action, NULL);//schedule an alarmalarm(1);//pausepause();
}
2.2 Reentrant Functions
2.3 Interrupting System call EINTR
2.4 SA_RESTART
2.5 Not all System Calls are Reentrant
20 Alarms, sigaction(), and Reentrant System Calls相关推荐
- 6.S081-Lab 2: System Calls
更好的阅读体验 官方材料:https://pdos.csail.mit.edu/6.S081/2021/labs/syscall.html 参考材料: https://th0ar.gitbooks.i ...
- 12 File and Device I/O using System Calls
1 System Calls, File Management and Device I/O 1.用户使用C standard library,调用malloc() calloc(),真实的空间申请是 ...
- iTron3学习笔记(一) System Calls of Memory Pool Management Functions
iTron3学习笔记(一) System Calls of Memory Pool Management Functions 1.创建固定内存池(Create Fixed Memory Pool) ...
- [mit6.1810] Lab system calls
文章目录 前言 Using gdb 题目 分析 system call tracing 题目 分析与代码 Sysinfo 题目 分析与代码 前言 在这个lab中我们会实现一些系统调用,这些系统调用类似 ...
- Lab system calls
6s081 Lab2: system calls 一开始看的时候看见这两个实验都是moderate,还以为挺简单.结果因为对xv6 book不熟悉,没有弄明白整个系统调用的过程,花了很多的时间去理解x ...
- System Calls [LKD 05]
无论什么系统,都会向user space提供一些interface,用来和kernel系统交互,从而可以实现某些特定功能,比如访问硬件,获取系统资源等等.通过定义好的interface访问系统,有助于 ...
- 最新论文笔记(+20):Biscotti_ A Blockchain System for Private and Secure Federated Learning / TPDS21
Biscotti: A Blockchain System for Private and Secure Federated Learning"译为"Biscotti:一个用于隐私 ...
- 6.S081——Lab2——system calls
0.Briefly Speaking 这是6.S081的第二个实验,目的主要是自己实现一些系统调用,上一个实验更多的是使用已有的设施去实现一些功能各异的程序,这需要我们对系统调用的过程有更加深入的理解 ...
- System calls
Kernel programming is vital for as long as new hardware is being designed and produced or old-obsole ...
最新文章
- 实现entity、dao 、service 、serviceImpl自动生成
- Smoke Test与Ad hoc Test
- matlab完全自学一本通 pdf,matlab r2014a自学一本通 MATLAB R2014a完全自学一本通 中文pdf扫描版[125MB] 下载-脚本之家...
- RedisTemplate和StringRedisTemplate使用
- 盛大游戏杯第十五届上海大学程序设计联赛暨上海金马五校赛
- jupyter配置到服务器_服务器端jupyter notebook映射到本地浏览器的操作
- ORA-01552 :非系统表空间 'xxxx'不能使用系统回退段
- 从源代码编译安装 Mono 2.4 和 MonoDevelop 2.0
- tarjan用法——割点
- java基础之继承(一)
- Lua 可变参数之arg与select
- linux文件管理命令详解
- 黑苹果显卡加速_谁说苹果macOS系统不适合3D,没有OC渲染器?
- 【数据可视化应用】绘制风玫瑰图(附Python代码)
- WPS 解决插入尾注后无法添加分节页符
- 网络 — MB/s、Mb/s、Mbps、Mbit/s、Kbps
- 找工作经验贴----转自cc98 (作者ID:qzz88 ) 仅为收藏,感谢原作者的经验分享
- vipkid怎么样?来自家长的真实评价
- 注册石墨文档无法连接服务器,石墨文档没有访问权限是怎么回事?权限解决方法看这里!...
- 云虚拟主机数据库连接和url重写
热门文章
- 初学者python笔记(内置函数_1)
- 相位延迟和群延迟的区别
- Heart Rate Estimate
- vue 判断一个数是否在数组中_高级前端进阶,vue如何实现$nextTick
- 医学方面的创业计划书_【就业创业】设计学院开展2019“汉军杯”大学生创业大赛 初评及复评工作...
- gitea无法连接mysql_Git push ERROR: Repository not found fatal:无法连接远程数据库
- python中 tolist_python 列表,数组,矩阵两两转换tolist()的实例
- win8计算机里没有用户,win8.1系统没有选择切换账户菜单怎么办|win8.1系统切换用户的方法...
- java poi 导出excel 速度慢_java POI技术之导出数据优化(15万条数据1分多钟)
- videocapture 保存图片_RoboMaster视觉教程OpenCV(二)读取视频图像与转换