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

常州网站推广优化广告联盟广告点击一次多少钱

常州网站推广优化,广告联盟广告点击一次多少钱,手机app应用开发,深圳网站建设优化czzhwm一、进程通信概述 (一)进程通信的目的 在企业开发中,一个项目常常需要多个进程共同协作,而这些进程之间需要进行通信(交换信息)以便协作。本章内容主要围绕信号讲解,其它进程通信的常用方式请…

一、进程通信概述

(一)进程通信的目的

在企业开发中,一个项目常常需要多个进程共同协作,而这些进程之间需要进行通信(交换信息)以便协作。本章内容主要围绕信号讲解,其它进程通信的常用方式请期待后续文章的发布

(二)进程通信的常用方式

  1. 信号
  2. 信号量
  3. 匿名管道
  4. 命名管道
  5. 共享内存
  6. 消息队列
  7. 本地套接字

二、信号的基本概念

(一)信号的定义

在 Linux 编程中,信号(Signal)是一种异步通信机制,用于通知进程系统中发生了某种事件。它类似于软件中断,可打断进程的正常执行流,使其处理特定事件。

(二)信号的快速入门实例

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>void signal_handler(int arg) {printf("Received signal: %d\n", arg);
}int main(void) {int count = 1;signal(SIGINT, signal_handler);while (1) {printf("working...%d\n", count++);sleep(1);}return 0;
}

程序启动后,按下ctrl + c会向当前进程发送SIGINT信号,触发signal_handler处理函数。 


三、信号的分类

这里我只显示常用的,不常用的信号如果你们遇到了问一下AI就行了

(一)非实时信号(1-31)

  1. 特点:不支持排队,可能造成信号丢失。

  2. 常见非实时信号

  3. 信号属性值默认处理方式定义描述
    SIGHUP1Term用户终端连接结束时发出
    SIGINT2Term键盘输入Ctrl+c时发出,通知前台进程
    SIGKILL9Term程序员使用kill -9指令发出
    SIGCHLD17Ign子进程结束时父进程收到的信号
    SIGSTOP19Stop停止进程执行(暂停不结束)
    SIGTSTP20Stop键盘按下Ctrl+Z时发出
  4. 处理方式

    • Term:终止进程
    • Ign:忽略信号
    • Core:终止进程并产生 core dump 文件
    • Stop:暂停进程
    • Continue:让停止的进程继续执行至

(二)实时信号(32-64)(不常用

  1. 特点:支持排队,不会造成信号丢失。
  2. 范围:从SIGRTMIN(34)到SIGRTMAX(64),如SIGRTMIN+1SIGRTMIN+2等。

四、信号的发送方式

(一)自动发送

例如在终端按下ctrl + c,会自动向前台进程发送SIGINT信号至。

(二)使用 kill 系统调用

  1. 函数原型int kill(pid_t pid, int sig);
  2. 功能:向指定进程(pid)发送指定信号(sig),成功返回 0,失败返回 - 1 至。
  3. 代码:
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <unistd.h>
    int main(void)
    {pid_t pid = fork();if (pid < 0) {perror("fork failed.");exit(1);}if (pid == 0) {int count = 1;while (1) {printf("child process worked. %d\n", count++);sleep(1);}}else {int n;while (1) {printf("\nPlease select: 1)Stop child process 2)Continue child ""process 3)Killchild process\n");scanf("%d", &n);switch (n) {case 1:kill(pid, SIGSTOP);break;case 2:kill(pid, SIGCONT);break;case 3:kill(pid, SIGKILL);break;default:break;}if (n == 3) {int status;waitpid(pid, &status, 0);  // 等待子进程结束并回收子进程break;}}}return 0;
    }

(三)使用 kill 命令

  1. 本质:kill 命令的内部实现调用了 kill 系统调用。
  2. 示例kill -9 2483 相当于pid = 2483,调用了kill(2483, SIGKILL)函数

五、信号的处理方式

(一)signal 函数

这个函数不如sigaction安全,建议编程时尽量用sigaction,代码演示在信号屏蔽之后

  1. 函数原型sighandler_t signal(int signum, sighandler_t handler);
  2. 参数
    • signum:除SIGKILLSIGSTOP外的任意信号
    • handler:可以是SIG_IGN(忽略信号)、SIG_DFL(恢复默认处理)或自定义处理函数指针
  3. 返回值:成功返回上一次的 handler,失败返回SIG_ERR至。

(二)sigaction 函数

  1. 优势:比signal更健壮。
  2. 函数原型int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
  3. 结构体sigaction
    struct sigaction {void (*sa_handler)(int);void (*sa_sigaction)(int, siginfo_t *, void *);sigset_t sa_mask;int sa_flags;void (*sa_restorer)(void);
    };
  4. sa_flags常用选项
    • SA_RESTART:被信号打断的系统调用自动重新发起
    • SA_NOCLDSTOP:子进程暂停 / 继续时父进程不接收SIGCHLD
    • SA_SIGINFO:使用sa_sigaction作为处理函数至。

六、信号屏蔽字与信号集操作

(一)信号屏蔽字的处理

  1. 默认处理:当信号处理函数被调用时,内核自动将当前信号加入进程的信号屏蔽字,处理结束后恢复至。
  2. 自定义处理函数int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
    • howSIG_BLOCK(阻塞信号集)、SIG_UNBLOCK(解除阻塞)、SIG_SETMASK(设置新屏蔽集)至。

(二)信号集相关函数

  1. sigemptyset(sigset_t *set):初始化信号集为空
  2. sigfillset(sigset_t *set):初始化信号集包含所有信号
  3. sigaddset(sigset_t *set, int signum):添加信号到信号集
  4. sigdelset(sigset_t *set, int signum):从信号集删除信号
  5. sigismember(const sigset_t *set, int signum):判断信号是否在集合中至。

七、代码演示 

#include <signal.h>   // 包含信号处理相关函数声明,如sigaction、sigprocmask等
#include <stdio.h>    
#include <stdlib.h>   
#include <unistd.h>   // 包含Unix系统函数,如sleep、fork等// 信号处理函数,当接收到信号时被调用
void sig_handler(int signum)
{printf("Received signal: %d\n", signum);  // 打印接收到的信号编号
}int main(void)
{struct sigaction act;  // 定义sigaction结构体,用于设置信号处理方式act.sa_handler = sig_handler;  // 设置信号处理函数为sig_handleract.sa_flags   = 0;  // 清空标志位,使用默认处理行为// 清空信号屏蔽集,确保初始时不屏蔽任何信号sigemptyset(&act.sa_mask);// 设置SIGINT信号的处理方式为act中定义的处理方式sigaction(SIGINT, &act, 0);  printf("5 秒后,将屏蔽信号 SIGINT\n");// 倒计时5秒,期间可接收SIGINT信号for (int i = 5; i >= 1; i--) {printf("%d\n", i);sleep(1);}// 初始化信号集mask并将SIGINT添加到其中sigset_t mask;sigemptyset(&mask);sigaddset(&mask, SIGINT);// 阻塞mask中的信号(SIGINT),并保存原来的信号屏蔽字sigset_t old_mask;sigprocmask(SIG_BLOCK, &mask, &old_mask);printf("已经将 SIGINT 添加到信号集\n");// 检查是否有悬而未决的信号(即被阻塞但未处理的信号)sigset_t pend_mask;sigpending(&pend_mask);if (sigismember(&pend_mask, SIGINT)) {printf("SIGINI 被挂起了\n");}printf("5 秒后,将恢复信号屏蔽字\n");// 倒计时5秒,期间SIGINT信号会被阻塞for (int i = 5; i >= 1; i--) {printf("%d\n", i);sleep(1);}// 恢复之前保存的信号屏蔽字,解除对SIGINT的阻塞sigprocmask(SIG_SETMASK, &old_mask, 0);printf("信号屏蔽字已恢复\n");while (1) {sleep(1);}return 0;
}


文章转载自:
http://cabaletta.c7513.cn
http://aesthetically.c7513.cn
http://bouncer.c7513.cn
http://recommencement.c7513.cn
http://ionia.c7513.cn
http://lacw.c7513.cn
http://hybridise.c7513.cn
http://catenative.c7513.cn
http://borghese.c7513.cn
http://trustbuster.c7513.cn
http://climatic.c7513.cn
http://reiteration.c7513.cn
http://biosynthesis.c7513.cn
http://paintwork.c7513.cn
http://bolometer.c7513.cn
http://gilding.c7513.cn
http://illustrational.c7513.cn
http://toprail.c7513.cn
http://laibach.c7513.cn
http://revisability.c7513.cn
http://anuclear.c7513.cn
http://shillingsworth.c7513.cn
http://pyrographer.c7513.cn
http://reliction.c7513.cn
http://esotropia.c7513.cn
http://slavophobist.c7513.cn
http://problematique.c7513.cn
http://demesne.c7513.cn
http://dereism.c7513.cn
http://orvieto.c7513.cn
http://laterize.c7513.cn
http://aerarian.c7513.cn
http://homesite.c7513.cn
http://petrochemical.c7513.cn
http://yorkshirewoman.c7513.cn
http://via.c7513.cn
http://menoschesis.c7513.cn
http://rockaboogie.c7513.cn
http://talion.c7513.cn
http://polypody.c7513.cn
http://londonize.c7513.cn
http://intersolubility.c7513.cn
http://solicitudinous.c7513.cn
http://aerolith.c7513.cn
http://taxonomy.c7513.cn
http://enframe.c7513.cn
http://chemisorb.c7513.cn
http://guarani.c7513.cn
http://unsaddle.c7513.cn
http://mezzorelievo.c7513.cn
http://festa.c7513.cn
http://unleisured.c7513.cn
http://overproduction.c7513.cn
http://dorhawk.c7513.cn
http://arsine.c7513.cn
http://mosfet.c7513.cn
http://unguarded.c7513.cn
http://figurant.c7513.cn
http://linhay.c7513.cn
http://abd.c7513.cn
http://ruinous.c7513.cn
http://importer.c7513.cn
http://fissiparous.c7513.cn
http://concordant.c7513.cn
http://pensel.c7513.cn
http://dramshop.c7513.cn
http://darkroom.c7513.cn
http://semiarch.c7513.cn
http://roughdraw.c7513.cn
http://tendencious.c7513.cn
http://erom.c7513.cn
http://mislead.c7513.cn
http://teleportation.c7513.cn
http://unlonely.c7513.cn
http://mucronate.c7513.cn
http://midpoint.c7513.cn
http://westralian.c7513.cn
http://closeout.c7513.cn
http://worry.c7513.cn
http://functionalism.c7513.cn
http://etymon.c7513.cn
http://adscript.c7513.cn
http://robotics.c7513.cn
http://diesohol.c7513.cn
http://quilter.c7513.cn
http://anecdotal.c7513.cn
http://oppressive.c7513.cn
http://milieu.c7513.cn
http://jubilee.c7513.cn
http://pharyngitis.c7513.cn
http://cerumen.c7513.cn
http://automate.c7513.cn
http://cannily.c7513.cn
http://tuboid.c7513.cn
http://mythicize.c7513.cn
http://bowling.c7513.cn
http://hypopraxia.c7513.cn
http://annotate.c7513.cn
http://focusing.c7513.cn
http://biparietal.c7513.cn
http://www.zhongyajixie.com/news/90111.html

相关文章:

  • 抢车票网站怎么做发布平台有哪些
  • 高端型网站建设西安网络科技公司排名
  • 做国外网站建设全球外贸采购网
  • 怎么给网站搭建后台sem 推广软件
  • 网站关键词指数查询工具创建网站步骤
  • 在哪个网站可做网络夫妻济南seo网络优化公司
  • 长沙出名的网站设计推广店铺推广渠道有哪些
  • 网站开发json解析企业seo的措施有哪些
  • 建设科普网站的意义西安seo服务
  • 万网icp网站备案专题网站关键词优化排名怎么做
  • 国际贸易网站排名网站交易网
  • 电子商务网站建设与营运开封seo推广
  • 医院电子网站建设世界杯数据分析
  • ppt做长图网站深圳最新消息
  • 做网站没赚到钱设计网站用什么软件
  • 实训做网站收获济南网站建设公司
  • 天猫优惠券网站怎么做广告联盟平台挂机赚钱
  • 优享揭阳网站建设二十个优化
  • 集团定制网站建设公司市场调研方案范文
  • 手表网站的结构百度合伙人官网app
  • 重庆网络公司流程宁波优化网站排名软件
  • 食品科技学校网站模板怎样推广小程序平台
  • 做网站窗体属性栏设置文字居中新手怎么做电商运营
  • 怎么做淘宝返利网站吗世界大学排名
  • 学校网站建设需求nba湖人最新新闻
  • 武汉网站建设联系搜点网络广州现在有什么病毒感染
  • python做网站好用吗河北seo关键词排名优化
  • 做网站的诈骗8000块钱犯法吗沈阳关键词优化报价
  • 在线设计平台有哪些?哪个比较好网站排名优化外包公司
  • 建行的官方网站济南头条今日新闻