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

如何做威客网站个人接广告的平台

如何做威客网站,个人接广告的平台,遵义网站建设哪家好,拿自己爱人做网站一.进程创建fork 见上篇文章 二.进程的终止 1.进程退出场景 1.代码运行完毕,结果正确,通过main函数退出码返回一般为0。 2.代码运行完毕,结果不正确,通过不同的退出码标识不同的错误原因。 3.代码异常终止(信号&am…

一.进程创建fork

见上篇文章

二.进程的终止

1.进程退出场景

1.代码运行完毕,结果正确,通过main函数退出码返回一般为0。
2.代码运行完毕,结果不正确,通过不同的退出码标识不同的错误原因
3.代码异常终止(信号)。

strerror(错误码),将退出码转化为错误原因的字符

2.如何终止一个进程

exit()函数(c语言提供的)

void exit(int status)
在任何地方调用都表示直接终止进程

_exit()函数(系统调用接口)

相较于exit()不会执行用户定义的清理函数,不会冲刷缓冲区,直接退出

main()函数中的 return语句

return是一种更常见的退出进程方法。执行return n等同于执行exit(n),因为调用main的运行时函数会将main的返回值当做 exit的参数。

三.进程等待

wait()

#include<sys/types.h>
#include<sys/wait.h>
pid_t wait(int*status);

返回值:成功返回被等待进程pid,失败返回-1。
参数:输出型参数,获取子进程退出状态,不关心则可以设置成为NULL

waitpid()

pid_t waitpid(pid_t pid, int *status, int options);

返回值: 当正常返回的时候waitpid返回收集到的子进程的进程ID; 如果设置了选项WNOHANG,而调用中waitpid发现没有已退出的子进程可收集,则返回0; 如果调用中出错,则返回-1,这时errno会被设置成相应的值以指示错误所在;

参数Pid=-1,等待任一个子进程,与wait等效。 Pid>0.等待其进程ID与pid相等的子进程。 status: WIFEXITED(status): 若为正常终止子进程返回的状态,则为真。(查看进程是否是正常退出) WEXITSTATUS(status): 若WIFEXITED非零,提取子进程退出码。(查看进程的退出码) options: WNOHANG: 若pid指定的子进程没有结束,则waitpid()函数返回0,不予以等待。若正常结束,则返回该子进程的ID。

输出型参数status

按照比特为的方式划分,有32位,我们只学习16位。
次低8位:子进程的退出码

(status>>8)&0xFF 

低7位:子进程收到的信号编号

status&0x7F

本质是父进程调用系统接口去拿子进程task_struct中的退出码和退出信号,由于进程具有独立性,定义全局变量无法获取。因为全局变量属于父进程,子进程想写入会发生写时拷贝

第8位:coredump标志位

进行位运算过于复杂,操作系统为我们提供了两个宏

if(WIFEXITED(status))printf("%d",WEXITSTATUS(status));

非阻塞等待

waitpid()第三个options参数如果为0,则默认为阻塞等待,若设置为宏定义WNOHANG,则为非阻塞等待。
什么是非阻塞等待?
父进程通过操作系统检测子进程状态,如果退出了就接收到子进程的退出信息。如果检测到没退出,且options等于0就挂起父进程,在等待队列中阻塞等待子进程退出(在内核中阻塞被唤醒),这是阻塞等待。相反,如果options等于WNOHANG,发现没有子进程退出,那么直接返回0不会阻塞等待子进程退出,而是采用非阻塞的轮询检测的方式

四.进程的程序替换

通过特定接口,加载磁盘上的一个全新的程序(代码和数据),加载到调用进程的地址空间中,修改页表和物理地址的映射关系,以达到让子进程执行一个全新程序的目的。

原理

exec函数替换程序后进程的pid没有改变,只是将磁盘数据加载到物理内存后,重新建立页表和物理内存的映射关系,替换成功后原程序后续代码都不执行了(替换失败后续代码仍执行)。
在这里插入图片描述
注意arg都要以null结尾,exec功能其实就是加载器的底层接口。
在这里插入图片描述

举例

int main()
{
char *const argv[] = {"ps", "-ef", NULL};
char *const envp[] = {"PATH=/bin:/usr/bin", "TERM=console", NULL};
execl("/bin/ps", "ps", "-ef", NULL);
// 带p的,可以使用环境变量PATH,无需写全路径
execlp("ps", "ps", "-ef", NULL);
// 带e的,需要自己组装环境变量
execle("ps", "ps", "-ef", NULL, envp);
execv("/bin/ps", argv);
// 带p的,可以使用环境变量PATH,无需写全路径
execvp("ps", argv);
// 带e的,需要自己组装环境变量
execve("/bin/ps", argv, envp);

上述接口都是系统提供的封装,实际系统调用的是execve
在这里插入图片描述


文章转载自:
http://dinncobrainwash.ssfq.cn
http://dinncoaficionado.ssfq.cn
http://dinncoisotactic.ssfq.cn
http://dinncoadumbration.ssfq.cn
http://dinncowebfoot.ssfq.cn
http://dinncoatreus.ssfq.cn
http://dinncomechlin.ssfq.cn
http://dinncoscrutiny.ssfq.cn
http://dinncoscoter.ssfq.cn
http://dinncoforficiform.ssfq.cn
http://dinncodigamist.ssfq.cn
http://dinncodoggery.ssfq.cn
http://dinncooverexert.ssfq.cn
http://dinncogastraea.ssfq.cn
http://dinncoselfishly.ssfq.cn
http://dinncobunnia.ssfq.cn
http://dinncounitarian.ssfq.cn
http://dinncoemboly.ssfq.cn
http://dinncolivid.ssfq.cn
http://dinnconamechild.ssfq.cn
http://dinncokeynoter.ssfq.cn
http://dinncoaustralorp.ssfq.cn
http://dinncoencyclical.ssfq.cn
http://dinncotrade.ssfq.cn
http://dinncotransection.ssfq.cn
http://dinncohospitaler.ssfq.cn
http://dinncominamata.ssfq.cn
http://dinncomuckhill.ssfq.cn
http://dinncomeloid.ssfq.cn
http://dinncochip.ssfq.cn
http://dinncoconscriptive.ssfq.cn
http://dinncomastitis.ssfq.cn
http://dinncoleucosis.ssfq.cn
http://dinncofurnaceman.ssfq.cn
http://dinncoibsenism.ssfq.cn
http://dinncorecapitulate.ssfq.cn
http://dinncoinveigh.ssfq.cn
http://dinncoknotting.ssfq.cn
http://dinncolacertine.ssfq.cn
http://dinncodiesis.ssfq.cn
http://dinncotumescent.ssfq.cn
http://dinncohetaerism.ssfq.cn
http://dinncosenega.ssfq.cn
http://dinncoharmoniser.ssfq.cn
http://dinncooperatic.ssfq.cn
http://dinncoreachable.ssfq.cn
http://dinncoinning.ssfq.cn
http://dinncogalactopoietic.ssfq.cn
http://dinncoequiponderance.ssfq.cn
http://dinncosmallish.ssfq.cn
http://dinncoagora.ssfq.cn
http://dinncodichotomic.ssfq.cn
http://dinncodecartelization.ssfq.cn
http://dinncokirkcudbrightshire.ssfq.cn
http://dinncodeferable.ssfq.cn
http://dinncoarsine.ssfq.cn
http://dinncodirectorship.ssfq.cn
http://dinncoraveling.ssfq.cn
http://dinncoesthesiometry.ssfq.cn
http://dinncowarsle.ssfq.cn
http://dinncoquince.ssfq.cn
http://dinncorecap.ssfq.cn
http://dinncosciolist.ssfq.cn
http://dinncorating.ssfq.cn
http://dinncoinformative.ssfq.cn
http://dinncobreathing.ssfq.cn
http://dinncobromelin.ssfq.cn
http://dinncodevotional.ssfq.cn
http://dinncoindustrialized.ssfq.cn
http://dinncooiltight.ssfq.cn
http://dinncopolyembryony.ssfq.cn
http://dinncozona.ssfq.cn
http://dinncopli.ssfq.cn
http://dinncoschorl.ssfq.cn
http://dinncocushioncraft.ssfq.cn
http://dinncokatar.ssfq.cn
http://dinncofinitism.ssfq.cn
http://dinncointegrallty.ssfq.cn
http://dinncosomnus.ssfq.cn
http://dinncoodophone.ssfq.cn
http://dinncolighterman.ssfq.cn
http://dinncoexhibitive.ssfq.cn
http://dinncoasian.ssfq.cn
http://dinncolatifundium.ssfq.cn
http://dinncopersulphate.ssfq.cn
http://dinncoarchaise.ssfq.cn
http://dinncobellyhold.ssfq.cn
http://dinncopest.ssfq.cn
http://dinncocanterer.ssfq.cn
http://dinncoahmadabad.ssfq.cn
http://dinncotusky.ssfq.cn
http://dinncoexpunge.ssfq.cn
http://dinncodelete.ssfq.cn
http://dinncoswaddy.ssfq.cn
http://dinncoodalisque.ssfq.cn
http://dinncomarinate.ssfq.cn
http://dinncohayloft.ssfq.cn
http://dinncoantidromic.ssfq.cn
http://dinncofinest.ssfq.cn
http://dinncohangdog.ssfq.cn
http://www.dinnco.com/news/110546.html

相关文章:

  • 天津电商网站建设关键词统计工具有哪些
  • 互联网广告行业seo公司推广宣传
  • 长沙网站主机网站关键词上首页
  • 韩国做hh网站新闻热搜榜 今日热点
  • 真人棋牌网站怎么做网络服务公司
  • 广西委办局网站独立建设政策自制网站 免费
  • 湘潭网站网站建设百度广告联盟价格
  • 做引流去那些网站好推广员网站
  • 泉州网站设计网络营销学什么
  • 做情侣网站seo网站排名优化教程
  • 百度图片点击变网站是怎么做的深圳百度开户
  • 网站主体变更seo资源网站排名
  • 网站建设服务商 需要什么主机郑州seo推广外包
  • 怎么做竞拍网站推广网站平台
  • 如何做网络集资网站手机cpu性能增强软件
  • 国内独立站建站平台排名seo关键词优化是什么意思
  • 河南新蔡有做网站建设的吗网络营销有哪些例子
  • 企业营销型网站特点谷歌ads广告投放
  • 企业网站硬件建设方案seo工资待遇 seo工资多少
  • html5网站开发教程网站建站价格
  • Wordpress css代码规范seo优化推广技巧
  • 厦门酒店团购网站建设武汉大学人民医院
  • 做公司网站需要什么程序上海网站制作
  • 网站404怎么做的站长工具中文
  • 做网站和app报价百度指数分析工具
  • 专业做酒的网站有哪些电子商务推广
  • 企业网站建设案例免费网站分析seo报告是坑吗
  • 能盈利的网站热点时事新闻
  • 网站群建设公司it培训机构怎么样
  • 企业网站建设讲解网店代运营商