1. 未决信号集与阻塞信号集(信号屏蔽字)
    阻塞信号集: 将某些信号加入集合,对他们设置屏蔽,当屏蔽x信号后,再收到该信号,该信号的处理将推后(解除屏蔽后)
    未决信号集:
    a. 信号产生,未决信号集中描述该信号的位立刻翻转为1,表信号处于未决状态。当信号被处理对应位翻转回为0。这一时刻往往非常短暂。
    b. 信号产生后由于某些原因(主要是阻塞)不能抵达。这类信号的集合称之为未决信号集。在屏蔽解除前,信号一直处于未决状态。
    相当于 阻塞信号集在未决信号集前面设置了一堵墙

  2. 系统api产生信号
    kill函数

#include <sys/types.h>
#include <signal.h>
int kill(pid_t pid, int sig);

参数介绍:
pid >0,要发送的进程ID
pid =0,代表当前进程组内所有进程
pid =-1, 代表有权限发送的所有进程
pid <-1, 代表 -pid对应组内所有进程
sig 对应的信号

kill函数代码示例

de <sys/types.h>
#include <signal.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>int main() {int i=0;pid_t pid;for(; i<5; ++i) {pid = fork();if(pid==0){break;}}if(i=2) {printf("son---%d will kill fatherProgress\n",i);sleep(5);kill(getppid(), SIGKILL);while (1) {sleep(1);}} if(i=5) {while(1) {printf("father ----\n");sleep(1);}}return 0;
}

–分割线–
alarm
man alarm

 #include <unistd.h>unsigned int alarm(unsigned int seconds);

alarm() arranges for a SIGALRM signal to be delivered to the calling
process in seconds seconds.
If seconds is zero, any pending alarm is canceled.
In any event any previously set alarm() is canceled.
alarm() 函数 给调用者(自己)发送 一个 SIGALRM 信号,在 seconds秒后。
如果 seconds是0, 取消之前的 设置的 alarm。

return返回值
返回之前设置的 alarm剩余的秒数,如果之前没有设置alarm,就返回0.

alarm代码示例:

#include <stdio.h>
#include <signal.h>
#include <unistd.h>int main() {int ret_1 = alarm(5);printf("%d\n", ret_1);sleep(2);int ret_2 = alarm(4);int num = 4;printf("%d\n", ret_2);while (1) {printf(" will ararm fater %d\n", num--);sleep(1);}return 0;
}

–分割线–
setitimer函数,周期性发送信号
man setitimer

#include <sys/time.h>
int getitimer(int which, struct itimerval *curr_value);
int setitimer(int which, const struct itimerval *new_value,
struct itimerval *old_value);

参数介绍:
which 三种选择

真实时间ITIMER_REAL    decrements in real time, and delivers SIGALRM upon expi‐ration.计算进程执行时间ITIMER_VIRTUAL decrements  only  when  the  process  is  executing, anddelivers SIGVTALRM upon expiration.计算进程执行 + 调度时间
ITIMER_PROF    decrements both when the process executes and  when  thesystem  is  executing on behalf of the process.  Coupledwith ITIMER_VIRTUAL, this timer is usually used to  pro‐file  the time spent by the application in user and ker‐nel space.  SIGPROF is delivered upon expiration.
struct itimerval {struct timeval it_interval; /* Interval for periodic timer */  周期定时器间隔struct timeval it_value;    /* Time until next expiration */ 下次执行时间
};struct timeval {time_t      tv_sec;         /* seconds */ 秒数suseconds_t tv_usec;        /* microseconds */ 微秒数
};

new_value 要设置的闹钟时间
old_value 原闹钟时间

return: 成功返回0, 失败-1,并设置errno
setitimer 代码示例:

#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>void catch(int sign) {if(sign == SIGALRM) {printf("catch signal is %d\n", sign);}
}
int main() {signal(SIGALRM, catch);struct itimerval new_value = {{3, 0},{1, 0}};setitimer(ITIMER_REAL, &new_value,  NULL);while (1){printf(" setitimer test\n");sleep(1);}return 0;
}

linux信号学习02相关推荐

  1. Linux 信号学习

    Linux 信号学习 信号量的基本概念 信号产生的条件 信号如何被处理 信号的异步特质 信号的分类 可靠信号/不可靠信号 实时信号/非实时信号 常见信号与默认行为 信号处理 `signal()` 函数 ...

  2. Linux操作系统学习02

    文件的增删改查 文件目录: 创建文件:touch 文件名 1.创建多个文件touch file{1..10}注:创建10个文件,文件名file0,file1 ......file102.创建多个目录m ...

  3. linux指令如何删除线程,linux基本命令学习02

    ============================================================================= a.txt c:abca.txt windo ...

  4. 【Linux系统编程】Linux信号列表

    00. 目录 文章目录 00. 目录 01. Linux信号编号 02. 信号简介 03. 特殊信号 04. 附录 01. Linux信号编号 在 Linux 下,每个信号的名字都以字符 SIG 开头 ...

  5. Linux shell 学习笔记(12)— linux 信号、后台运行脚本、作业控制、定时运行任务

    1. 处理信号 1.1 Linux 信号 常见的 Linux 信号如下表所示: 信号 值 描述 1 SIGHUP 挂起进程 2 SIGINT 终止进程 3 SIGQUIT 停止进程 9 SIGKILL ...

  6. 【嵌入式Linux学习七步曲之第五篇 Linux内核及驱动编程】Linux信号机制分析

    Linux信号机制分析 Sailor_forever  sailing_9806@163.com 转载请注明 http://blog.csdn.net/sailor_8318/archive/2008 ...

  7. linux系统管理学习笔记之三----软件的安装

    linux系统管理学习笔记之三----软件的安装 2009-12-29 19:10:02 标签:linux 系统管理 [推送到技术圈] 版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 ...

  8. 鸟哥的linux 实训教程,鸟哥的Linux基础学习实训教程

    1.理想的Linux上机实践课程 每周一次.每次三小时的学与练 本书所有例题讲解,均经过鸟哥在大专院校实施多年来的测试,对于学生的理解具有相当满意的效果. 2. 提供一致性教学环境 让学习者不再有陌生 ...

  9. Linux 系统学习梳理_【All】

    作者:小a玖拾柒 出处:http://www.cnblogs.com/ftl1012/ 第一部分---基础学习 00.Linux操作系统各版本ISO镜像下载 00.Linux系统下安装Vmware(虚 ...

最新文章

  1. 可以弹的钢琴,很不错(转)
  2. STM8L编程环境官方库+STVD+COSMIC+ST-Link
  3. dump文件分析工具_使用这个 Python 工具分析你的 Web 服务器日志文件 | Linux 中国...
  4. 如何将tensorflow-yolov3(YunYang1994).txt 坐标转换成yolo的标注(annotations)
  5. asp.net学习资源汇总
  6. 二维动态数组定义及二维静态数组与**P的区别
  7. .net core 2.1 mysql_ASP.NET Core 2.2 + MySQL + DB First
  8. Linux更改文件及目录权限问题
  9. 程序员求职之道(《程序员面试笔试宝典》)之民间的企业排名的可信度到底有多大?...
  10. python_图像去畸变/图像矫正
  11. 计算机桌面颜色如何设置标准,教你把电脑屏幕设置成可以保护眼睛的颜色
  12. [笑话]1+1等于几?(新版)
  13. CRM - 用户管理
  14. 软件开发的功能性需求和非功能性需求
  15. 2022.01.02 Acwing寒假每日一题 笨拙的手指
  16. 研究生联系导师需要注意什么
  17. Java中getBytes()方法--使用详解
  18. SQL注入-二次注入和多语句注入
  19. svn分支介绍和使用
  20. C/C++黑魔法-没有临时值的交换

热门文章

  1. 尝试Office 2003 VSTO的开发、部署
  2. Ubuntu下tftp服务器的搭建
  3. linux 进程与锁,linux 中的进程与锁
  4. 下来安成功 打开一直白屏_推广人透露:戈洛夫金2021年可能与安德拉德上演拳王统一战...
  5. 7月9日王者荣耀服务器维护,王者荣耀 7月9日体验服停机更新公告
  6. git安装后找不见版本_无法安装最新版本的Gitlab
  7. CSDN挑战编程——《绝对值最小》
  8. Win32ASm学习[1]:RadASm下测试Debug
  9. python读取文本文件的三种方法
  10. 栈的应用--括号匹配的检验