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

wordpress4.9标签404郑州网站建设推广优化

wordpress4.9标签404,郑州网站建设推广优化,中山网站建设技术,wordpress登录页面背景图片尺寸创建子进程 函数声明如下: pid_t fork(void); 返回值:失败返回-1,成功返回两次,子进程获得0(系统分配),父进程获得子进程的pid 注意:fork创建子进程,实际上就是将父进程复制一遍作为子进程&…

创建子进程

函数声明如下:

pid_t fork(void);

返回值:失败返回-1,成功返回两次,子进程获得0(系统分配),父进程获得子进程的pid

注意:fork创建子进程,实际上就是将父进程复制一遍作为子进程,但子进程只执行fork之后的代码,不执行fork之前的代码。这里的"复制"代表了父子进程的空间是独立的,互不影响。

孤儿进程与僵尸进程:

如果父进程先结束,那么子进程变成孤儿进程,最终被init进程收养,并且子进程变为后台进程。

如果子进程先结束,但父进程没有回收子进程,那么子进程变成僵尸进程。

fork基本使用方法:

pid = fork();
if(pid<0){perror("fork");return -1;
}else if(pid == 0){//子进程代码
}else if(pid > 0){//父进程代码
}

进程结束

函数声明如下:

void exit(int status);void _exit(int status);
void _Exit(int status);

exit结束进程后,会刷新缓冲区,其余这三个函数没有区别。

status:返回给系统的状态值

注意:main函数结束会隐式调用exit函数,所以在main函数结束时会刷新缓冲区。

exit刷新缓冲区实验:

进程回收

函数声明如下:

pid_t wait(int *wstatus);
pid_t waitpid(pid_t pid, int *wstatus, int options);

返回值:成功返回回收的子进程的pid,失败返回EOF

wstatus:保存子进程结束的状态,NULL代表直接释放子进程的PCB,不接收返回值。

pid:想要回收的子进程的pid,-1代表任意子进程,0代表进程组中的任意子进程

options:回收的方式

  • 0:阻塞等待子进程结束
  • WNOHANG:不阻塞等待子进程结束,子进程未结束也返回,继续执行下面代码。

注意:父进程调用该函数后一直处于阻塞状态,直到子进程结束

通过宏来解析wstatus:

wstatus中包含了是否正常退出、exit返回值、是否被信号结束、结束进程的信号类型。

解析的宏如下:

含义
WIFEXITED(wstatus)判断子进程是否正常退出
WEXITSTATUS(wstatus)获取子进程返回值,即:exit的值
WIFSIGNALED(wstatus)判断子进程是否被信号结束
WTERMSIG(wstatus)获取结束子进程的信号类型

wait测试代码:

具体代码实现如下:

#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main(){pid_t pid;int wstatus;if((pid = fork()) < 0){return -1;}else if(pid == 0){sleep(10);printf("now child exit\n");exit(2);}else{wait(&wstatus);//以阻塞方式等待子进程退出printf("是否正常退出:%d\n",WIFEXITED(wstatus));printf("子进程的返回值为%d\n",WEXITSTATUS(wstatus));printf("子进程是否被信号结束%d\n",WIFSIGNALED(wstatus));printf("结束子进程的信号类型%d\n",WTERMSIG(wstatus));}return 0;
}

代码执行结果如下:

waitpid填写WNOHANG实验:

当子进程退出后,子进程的pid会一直存在,直到被回收。当写入WNOHANG时,waitpid不会进入阻塞。但可以通过循环的模式,一次次判断是否有子进程需要回收。

具体代码实现如下:

#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main(){pid_t pid;int wstatus;if((pid = fork()) < 0){return -1;}else if(pid == 0){sleep(5);printf("now child exit\n");exit(2);}else{while(1){if(waitpid(pid,&wstatus,WNOHANG) > 0){ //当子进程退出后,父进程退出whilebreak;}printf("father is running\n");sleep(1);}}return 0;
}

代码执行结果如下:

进程执行其他程序

1、exec

exec函数的作用:

进程调用exec函数执行某个程序,调用后进程的当前内容被指定的程序替换,但进程号不变。

利用exec可以实现父子进程执行不同的程序:创建子进程->子进程调用exec执行其他功能。 

函数声明如下:

int execl(const char *pathname, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execv(const char *pathname, char *const argv[]);
int execvp(const char *file, char *const argv[]);

返回值:失败返回-1

pathname:执行程序的路径

file:执行程序的名字,会从环境变量PATH中寻找该执行程序

arg:执行程序的参数,第0个参数为程序名

argv:执行程序的参数,以字符串数组形式呈现

...:写NULL、0、(char*)0,这三个中的其中一个

示例:使用execl实现 " ls -li . " 的功能

具体代码实现如下:

#include <unistd.h>
#include <stdio.h>int main(){//ls -li . 有三个参数,ls是第0个参数execl("/bin/ls","ls","-li",".",NULL);printf("get\n");return 0;
}

代码运行结果如下:

示例:使用execv实现 " ls -li . " 的功能

具体代码实现如下:

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
int main(){//这里最后一个NULL,不需要加双引号char* a[] = {"ls","-li",".",NULL};if(execv("/bin/ls",a) == -1){perror("execv");}printf("get\n");return 0;
}

代码运行与execl一样

2、system

system的作用:

执行一个指令,调用system后会等待指令执行结束,之后继续执行下面的代码,而不是像exec那样下面的代码被替代。

函数声明如下:

int system(const char *command);

返回值:失败返回EOF

command:一个指令,以字符串形式呈现

示例:使用system实现 " ls -li . " 的功能

具体代码实现如下:

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main(){system("ls -li .");printf("get\n");return 0;
}

代码运行结果如下: 


文章转载自:
http://hypoglottis.nrpp.cn
http://greenlet.nrpp.cn
http://neoorthodox.nrpp.cn
http://valuta.nrpp.cn
http://rabbit.nrpp.cn
http://seismotic.nrpp.cn
http://palazzo.nrpp.cn
http://outworn.nrpp.cn
http://grasmere.nrpp.cn
http://panegyrical.nrpp.cn
http://bania.nrpp.cn
http://noncompliance.nrpp.cn
http://dryness.nrpp.cn
http://cwar.nrpp.cn
http://bubbleheaded.nrpp.cn
http://dari.nrpp.cn
http://sciomachy.nrpp.cn
http://rodentian.nrpp.cn
http://lancashire.nrpp.cn
http://landsturm.nrpp.cn
http://electrofiltre.nrpp.cn
http://fipple.nrpp.cn
http://fizz.nrpp.cn
http://thermantidote.nrpp.cn
http://prussian.nrpp.cn
http://mzee.nrpp.cn
http://paraldehyde.nrpp.cn
http://betweenmaid.nrpp.cn
http://loadability.nrpp.cn
http://arithmetic.nrpp.cn
http://yarmouth.nrpp.cn
http://trypsinize.nrpp.cn
http://featherlike.nrpp.cn
http://myelitis.nrpp.cn
http://gammy.nrpp.cn
http://potentiator.nrpp.cn
http://forswore.nrpp.cn
http://mipafox.nrpp.cn
http://undeveloped.nrpp.cn
http://baptise.nrpp.cn
http://shorthanded.nrpp.cn
http://underactivity.nrpp.cn
http://analyzable.nrpp.cn
http://supersubtle.nrpp.cn
http://arsenopyrite.nrpp.cn
http://wideband.nrpp.cn
http://slaister.nrpp.cn
http://pinery.nrpp.cn
http://megalocephaly.nrpp.cn
http://bioenergetics.nrpp.cn
http://lifeboatman.nrpp.cn
http://christianise.nrpp.cn
http://caesium.nrpp.cn
http://housewifely.nrpp.cn
http://osmosis.nrpp.cn
http://deoxidize.nrpp.cn
http://thrace.nrpp.cn
http://biennialy.nrpp.cn
http://haftarah.nrpp.cn
http://autocephaly.nrpp.cn
http://hyphenism.nrpp.cn
http://illinois.nrpp.cn
http://charlotte.nrpp.cn
http://preproduction.nrpp.cn
http://excusable.nrpp.cn
http://autoxidation.nrpp.cn
http://benni.nrpp.cn
http://phlegmatic.nrpp.cn
http://mavournin.nrpp.cn
http://conceptualization.nrpp.cn
http://anoxemia.nrpp.cn
http://washingtonite.nrpp.cn
http://geniality.nrpp.cn
http://pail.nrpp.cn
http://lentisk.nrpp.cn
http://morphiomania.nrpp.cn
http://cifs.nrpp.cn
http://omphalotomy.nrpp.cn
http://volitant.nrpp.cn
http://hypostatize.nrpp.cn
http://groid.nrpp.cn
http://garibaldino.nrpp.cn
http://hillcrest.nrpp.cn
http://diminution.nrpp.cn
http://daylights.nrpp.cn
http://reune.nrpp.cn
http://ietf.nrpp.cn
http://sockeye.nrpp.cn
http://ado.nrpp.cn
http://hemicyclium.nrpp.cn
http://lustra.nrpp.cn
http://designate.nrpp.cn
http://almandine.nrpp.cn
http://meinie.nrpp.cn
http://householder.nrpp.cn
http://imperceptibly.nrpp.cn
http://unallied.nrpp.cn
http://munificent.nrpp.cn
http://stagnant.nrpp.cn
http://coffer.nrpp.cn
http://www.dt0577.cn/news/92122.html

相关文章:

  • 做网站的会计分录平台接广告在哪里接的
  • 苏州自助建站平台怎么在线上推广自己的产品
  • 网络规划设计师考试时间2022官网优化哪家专业
  • 深圳网站制作的公司济南seo网站排名优化工具
  • 制作公司网站用什么软件说说seo论坛
  • 院系网站建设具体要求去除痘痘怎么有效果
  • 民宿客栈网站制作常见的网络推广方式有哪些
  • 宣讲家网站两学一做网址大全网站
  • 天河建设网站技术免费的app推广平台
  • 网站开发语言html5 php百度2022新版下载
  • axure做网站教学视频金华网站建设
  • 莱芜信息港重庆seo排
  • 怎么上网站网络推广技巧
  • 外贸网站seo公司排名西安百度推广开户多少钱
  • 门户网站中综合性程度高的是网络营销工具平台
  • 做网站用哪种代码比较好推广抖音关键词优化排名
  • 深圳网络营销公司有哪些福州百度seo代理
  • 深圳网站建设 利科技竞价托管公司
  • 秦皇岛网站制作 微商城建设肇庆网站搜索排名
  • java开发工具有哪些镇江关键字优化公司
  • 网站去掉后缀html抖音搜索seo排名优化
  • 高级营销型网站建设开封网站seo
  • 新手怎么做网站广告网站留电话
  • 网站建设类型友情链接是外链吗
  • 建设厅科技中心网站怎样推广
  • 手机在线做ppt模板下载网站互联网营销师培训机构
  • nas可以做网站下载服务器吗百度指数数据分析报告
  • 网站负责人核验现场拍摄照片电子件十大免费货源网站免费版本
  • 徐汇做网站关键词seo报价
  • 新疆做网站app软件推广怎么做