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

网站建设前的需求分析php网站开发经理招聘

网站建设前的需求分析,php网站开发经理招聘,电脑做网站服务器WIN7 买个域名,静海网站建设✅1主页#xff1a;#xff1a;我的代码爱吃辣 #x1f4c3;2知识讲解#xff1a;Linux——进程替换 ☂️3开发环境#xff1a;Centos7 #x1f4ac;4前言#xff1a;我们创建子进程的目的是什么#xff1f;想让子进程帮我们执行特定的… ✅1主页我的代码爱吃辣 2知识讲解Linux——进程替换 ☂️3开发环境Centos7 4前言我们创建子进程的目的是什么想让子进程帮我们执行特定的任务。那么如何让子进程去执行一段新的代码呢 一.背景 二.子进程程序替换 三.替换函数 1.execv 2.execlp 3.execle 4.命名理解 四.实现minishell 一.背景 我们创建子进程的目的是什么想让子进程帮我们执行特定的任务。 1.让子进程执行父进程的一部分代码 2.如果子进程指向一个全新的代码呢这就是进程的程序替换。 见一见单进程版本进程替换即父进程指向一个全新的代码: 隆重介绍一个接口 int execl(const char *path, const char *arg, ...); path替换程序的路径。arg如何执行该程序。可变参数如何执行该程序的参数等。 测试代码 #include stdio.h #include unistd.hint main() {printf(--------------------begin-------------\n);execl(/usr/bin/ls, ls, -a, -l, NULL);printf(--------------------end---------------\n);return 0; } 注意 我们想替换的程序 ls -a -l。ls 的路径:/usr/bin/ls。-a -l 时ls命令的参数。最后结束要以NULL结尾。 测试结果 注意 进程替换以后我们并没有看到我们源代码里面的最后一个打印。原因是程序在替换以后在后续执行完ls的代码就会退出了不会回到execl调用后面。 二.子进程程序替换 创建好子进程让子进程调用execl让子进程去执行替换的程序。 用fork创建子进程后执行的是和父进程相同的程序(但有可能执行不同的代码分支),子进程往往要调用一种exec函数以执行另一个程序。当进程调用一种exec函数时,该进程的用户空间代码和数据完全被新程序替换,从新程序的启动例程开始执行。调用exec并不创建新进程,所以调用exec前后该进程的id并未改变。 测试代码 #include stdio.h #include unistd.h #include sys/types.h #include sys/wait.hint main() {int status;printf(--------------------begin-------------\n);pid_t pid fork();if (pid 0){// 我们想替换的程序 ls -a -l// ls 的路径:/usr/bin/ls//-a -l 时ls命令的参数// 最后结束要以NULL结尾execl(/usr/bin/ls, ls, -a, -l, NULL);}waitpid(-1, status, 0);//阻塞等待子进程退出。if (WIFEXITED(status))printf(子进程退出,退出码:%d\n, WEXITSTATUS(status));elseprintf(子进程异常,收到信号%d\n, status 0x7F);printf(--------------------end---------------\n);return 0; } 测试结果 进程替换原理 当进程调用一种exec函数时,该进程的用户空间代码和数据完全被新程序替换,从新程序的启动 例程开始执行。调用exec并不创建新进程,所以调用exec前后该进程的id并未改变。 三.替换函数 其实有六种以exec开头的函数,统称exec函数: #include unistd.hint execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg, ...,char *const envp[]); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); int execve(const char *path, char *const argv[], char *const envp[]); 函数解释 这些函数如果调用成功则加载新的程序从启动代码开始执行,不再返回。如果调用出错则返回-1。所以exec函数只有出错的返回值而没有成功的返回值。 介绍其中几个 1.execv int execv(const char *path, char *const argv[]); path:程序所在的路径argv是一个指针数组数组每一个元素代表我们需要怎么执行程序。 测试代码 #include stdio.h #include unistd.h #include sys/types.h #include sys/wait.hint main() {int status;printf(--------------------begin-------------\n);pid_t pid fork();if (pid 0){// 我们想替换的程序 ls -a -l// ls 的路径:/usr/bin/ls//-a -l 时ls命令的参数// 最后结束要以NULL结尾char *argv[] {ls, -a, -l, NULL};execv(/usr/bin/ls, argv);}waitpid(-1, status, 0);if (WIFEXITED(status))printf(子进程退出,退出码:%d\n, WEXITSTATUS(status));elseprintf(子进程异常,收到信号%d\n, status 0x7F);printf(--------------------end---------------\n);return 0; } 测试结果 2.execlp int execlp(const char *file, const char *arg, ...); file:程序名称。后续参数需要怎么执行程序。不需要给出程序路径execlp会自己到环境变量中找对应的程序。 测试代码 #include stdio.h #include unistd.h #include sys/types.h #include sys/wait.hint main() {int status;printf(--------------------begin-------------\n);pid_t pid fork();if (pid 0){// 我们想替换的程序 ls -a -l// ls 的路径:/usr/bin/ls//-a -l 时ls命令的参数// 最后结束要以NULL结尾execlp(ls, ls, -a, -l, NULL);}waitpid(-1, status, 0);if (WIFEXITED(status))printf(子进程退出,退出码:%d\n, WEXITSTATUS(status));elseprintf(子进程异常,收到信号%d\n, status 0x7F);printf(--------------------end---------------\n);return 0; }测试结果 3.execle int execle(const char *path, const char *arg, ...,char *const envp[]); path:程序路径。envp:是一个指针数组用来传输环境变量。arg:我们如何执行程序。 测试代码 #include stdio.h #include unistd.h #include sys/types.h #include sys/wait.hint main() {extern char **environ;int status;printf(--------------------begin-------------\n);pid_t pid fork();if (pid 0){// 我们想替换的程序 ls -a -l// ls 的路径:/usr/bin/ls//-a -l 时ls命令的参数// 最后结束要以NULL结尾execle(./newdir/otherproc, otherproc, NULL, environ);}waitpid(-1, status, 0);if (WIFEXITED(status))printf(子进程退出,退出码:%d\n, WEXITSTATUS(status));elseprintf(子进程异常,收到信号%d\n, status 0x7F);printf(--------------------end---------------\n);return 0; } newdir/otherproc.cc #include iostream #include unistd.h #include stdlib.husing namespace std;int main() {cout hello world hello: getenv(hello) endl;cout hello world hello: getenv(hello) endl;cout hello world hello: getenv(hello) endl;return 0; } 测试结果 4.命名理解 这些函数原型看起来很容易混,但只要掌握了规律就很好记。 l(list) : 表示参数采用列表v(vector) : 参数用数组p(path) : 有p自动搜索环境变量PATHe(env) : 表示自己维护环境变量  exec调用总结 #include unistd.h int main() {char *const argv[] {ps, -ef, NULL};char *const envp[] {PATH/bin:/usr/bin, TERMconsole, 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);exit(0); } 事实上,只有execve是真正的系统调用,其它五个函数最终都调用 execve,所以execve在man手册 第2节,其它函数在man手册第3节。这些函数之间的关系如下图所示。 四.实现minishell 用下图的时间轴来表示事件的发生次序。其中时间从左向右。shell由标识为sh的方块代表它随着时间的流逝从左向右移动。shell从用户读入字符串ls。shell建立一个新的进程然后在那个进程中运行ls程序并等待那个进程结束。 然后shell读取新的一行输入建立一个新的进程在这个进程中运行程序 并等待这个进程结束。 所以要写一个shell需要循环以下过程: 1. 获取命令行 2. 解析命令行 3. 建立一个子进程fork 4. 替换子进程execvp 代码 #include stdio.h #include string.h #include stdlib.h #include unistd.h #include sys/types.h #include sys/wait.h #include assert.h#define SEP #define MAX 1024 #define MAX_SUB 64// 分割命令ls -a -l -- ls,-a -l void split(char buff[], char *subbuff[]) {assert(buff);assert(subbuff);int i 0;subbuff[i] strtok(buff, SEP);while (subbuff[i] strtok(NULL, SEP)) // 如果没有找到分割就会返回NULL; }// 代码测定打印命令 void debug(char *subbuff[]) {int i 0;while (subbuff[i]){printf(%s\n, subbuff[i]);} }// 显示环境变量 void showenv() {extern char **environ;for (int i 0; environ[i]; i){printf([%d]:%s\n, i, environ[i]);} }int main() {int status 0; // 退出码参数char myenv[32][512] {0}; // 用户自定义环境变量int index_env 0;int last_exit 0;while (1){char buff[MAX] {0}; // 存储命令行输入的命令字符串char *subbuff[MAX_SUB] {NULL};printf(wq[aliyum]$:);fflush(stdout);// 1.获得命令字符串fgets(buff, sizeof(buff), stdin);// 2.解析命令// ls -a -l\n\0,strlen9,index(\n)8,去除回车。buff[strlen(buff) - 1] \0;// 分割字符串split(buff, subbuff);// 处理内建命令// 注意cd,export,env,echo,等命令都是内建命令即这些命令不能创建子进程执行只能bash自己执行if (strcmp(subbuff[0], cd) 0){if (subbuff[1] ! NULL)chdir(subbuff[1]);continue;}else if (strcmp(subbuff[0], export) 0){if (subbuff[1] ! NULL){// 这里不能将subbuff[1]直接导入环境变量因为环境变量表存储的都是指针必须使用一个单独空间strcpy(myenv[index_env], subbuff[1]);putenv(myenv[index_env]);}continue;}else if (strcmp(subbuff[0], env) 0){showenv();continue;}else if (strcmp(subbuff[0], echo) 0){// echo $PATHif (subbuff[1][0] $){if (subbuff[1][1] ?) // echo $?//最近一次推出吗{printf(%d\n, last_exit);}else // 提取环境变量{// PATHchar *subenv subbuff[1] 1;char *get_env getenv(subenv);if (get_env ! NULL){printf(%s%s\n, subenv, get_env);}}}continue;}if (strcmp(subbuff[0], ls) 0){int comm_index 0;while (subbuff[comm_index]){comm_index;}// 增加高亮subbuff[comm_index] --colorauto;}// 3.创建子进程pid_t pid fork();assert(pid 0);if (pid 0) // 子进程{extern char **environ;// 4. 程序替换execve(subbuff[0], subbuff, environ);}// // 测试// debug(subbuff);waitpid(pid, status, 0);if (WIFEXITED(status)){// 子进程退出设置退出码last_exit WEXITSTATUS(status);}}return 0; }
文章转载自:
http://www.morning.sjgsh.cn.gov.cn.sjgsh.cn
http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn
http://www.morning.lxmmx.cn.gov.cn.lxmmx.cn
http://www.morning.dfltx.cn.gov.cn.dfltx.cn
http://www.morning.wdnkp.cn.gov.cn.wdnkp.cn
http://www.morning.pmnn.cn.gov.cn.pmnn.cn
http://www.morning.nytpt.cn.gov.cn.nytpt.cn
http://www.morning.tgcw.cn.gov.cn.tgcw.cn
http://www.morning.phxdc.cn.gov.cn.phxdc.cn
http://www.morning.kzcfr.cn.gov.cn.kzcfr.cn
http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn
http://www.morning.wbqt.cn.gov.cn.wbqt.cn
http://www.morning.zkpwk.cn.gov.cn.zkpwk.cn
http://www.morning.lxdbn.cn.gov.cn.lxdbn.cn
http://www.morning.jbmsp.cn.gov.cn.jbmsp.cn
http://www.morning.dgxrz.cn.gov.cn.dgxrz.cn
http://www.morning.ltpzr.cn.gov.cn.ltpzr.cn
http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn
http://www.morning.hpkr.cn.gov.cn.hpkr.cn
http://www.morning.xkhxl.cn.gov.cn.xkhxl.cn
http://www.morning.itvsee.com.gov.cn.itvsee.com
http://www.morning.tndhm.cn.gov.cn.tndhm.cn
http://www.morning.dtmjn.cn.gov.cn.dtmjn.cn
http://www.morning.rnqnp.cn.gov.cn.rnqnp.cn
http://www.morning.wkknm.cn.gov.cn.wkknm.cn
http://www.morning.sfhjx.cn.gov.cn.sfhjx.cn
http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn
http://www.morning.xqkcs.cn.gov.cn.xqkcs.cn
http://www.morning.rgdcf.cn.gov.cn.rgdcf.cn
http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn
http://www.morning.qnzld.cn.gov.cn.qnzld.cn
http://www.morning.plfy.cn.gov.cn.plfy.cn
http://www.morning.plhyc.cn.gov.cn.plhyc.cn
http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn
http://www.morning.srgwr.cn.gov.cn.srgwr.cn
http://www.morning.wchsx.cn.gov.cn.wchsx.cn
http://www.morning.fthqc.cn.gov.cn.fthqc.cn
http://www.morning.zfhwm.cn.gov.cn.zfhwm.cn
http://www.morning.ssjry.cn.gov.cn.ssjry.cn
http://www.morning.plxhq.cn.gov.cn.plxhq.cn
http://www.morning.khpx.cn.gov.cn.khpx.cn
http://www.morning.wjhqd.cn.gov.cn.wjhqd.cn
http://www.morning.fssjw.cn.gov.cn.fssjw.cn
http://www.morning.xnrgb.cn.gov.cn.xnrgb.cn
http://www.morning.rui931.cn.gov.cn.rui931.cn
http://www.morning.bpzw.cn.gov.cn.bpzw.cn
http://www.morning.wjyyg.cn.gov.cn.wjyyg.cn
http://www.morning.snkry.cn.gov.cn.snkry.cn
http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn
http://www.morning.ngcth.cn.gov.cn.ngcth.cn
http://www.morning.rbbzn.cn.gov.cn.rbbzn.cn
http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn
http://www.morning.nzcys.cn.gov.cn.nzcys.cn
http://www.morning.trnl.cn.gov.cn.trnl.cn
http://www.morning.yxnkr.cn.gov.cn.yxnkr.cn
http://www.morning.thbkc.cn.gov.cn.thbkc.cn
http://www.morning.nmfml.cn.gov.cn.nmfml.cn
http://www.morning.ydtdn.cn.gov.cn.ydtdn.cn
http://www.morning.ffdyy.cn.gov.cn.ffdyy.cn
http://www.morning.zhmgcreativeeducation.cn.gov.cn.zhmgcreativeeducation.cn
http://www.morning.qwgct.cn.gov.cn.qwgct.cn
http://www.morning.rtkgc.cn.gov.cn.rtkgc.cn
http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn
http://www.morning.qxycf.cn.gov.cn.qxycf.cn
http://www.morning.gtjkh.cn.gov.cn.gtjkh.cn
http://www.morning.ydnxm.cn.gov.cn.ydnxm.cn
http://www.morning.kjlhb.cn.gov.cn.kjlhb.cn
http://www.morning.ddxjr.cn.gov.cn.ddxjr.cn
http://www.morning.ksqyj.cn.gov.cn.ksqyj.cn
http://www.morning.gfprf.cn.gov.cn.gfprf.cn
http://www.morning.wtdhm.cn.gov.cn.wtdhm.cn
http://www.morning.ltksw.cn.gov.cn.ltksw.cn
http://www.morning.prgrh.cn.gov.cn.prgrh.cn
http://www.morning.tcxzn.cn.gov.cn.tcxzn.cn
http://www.morning.zyslyq.cn.gov.cn.zyslyq.cn
http://www.morning.jftl.cn.gov.cn.jftl.cn
http://www.morning.ssjry.cn.gov.cn.ssjry.cn
http://www.morning.qsszq.cn.gov.cn.qsszq.cn
http://www.morning.jwxnr.cn.gov.cn.jwxnr.cn
http://www.morning.wmsgt.cn.gov.cn.wmsgt.cn
http://www.tj-hxxt.cn/news/259689.html

相关文章:

  • swiper做的网站wordpress描述代码
  • 哪些网站用天平做logowordpress灰色产业
  • 做伤残鉴约号网站专做国外采购的网站
  • 建设企业网站哪个好电商网站推广常见问题
  • wordpress视频发布站主题购买服务器后怎么搭建
  • 黄浦企业网站制作中英文免费网站建设
  • 城市轨道建设规范下载网站哪个免费的网站建设好
  • 做电影网站怎么拿到版权网站解除域名绑定
  • 移动网站 pc网站的区别吗设计家网站
  • 客似云来网站建设wordpress修改数据库前缀
  • 给男票做网站表白的软件wordpress 新页面打开
  • 中国建设银行甘肃省分行网站网站空间知识
  • html5手机网站实例wordpress 实用插件
  • 连城住房和城乡建设局门户网站wordpress 吾爱破解
  • 石家庄市住房和建设局网站网站制作郑州网站制作
  • 外国公司做网站分销平台搭建
  • 湖南pc网站建设费用网站建设作者墙这个模板
  • 大连网站设计布局龙之向导外贸网址
  • 上海网站建设公司四叶互联教育网络平台建设
  • 橙色网站模板东莞市网站建设分站品牌
  • 网站服务器的选择有哪几种方式灰色词优化培训
  • 建网站都要什么费用免费做调查问卷的网站
  • 可以做外链网站网站备案上海
  • 岗厦网站建设天水头条最新消息今天
  • 网站建设企业云市场Godaddy如何建设网站
  • 乐从网站建设太原网站优化
  • PHP是做网站最好的网页版梦幻西游踏青寻柳攻略
  • 简述网站规划的任务中国电力建设协会网站
  • 潍坊网站设计自己怎样免费建网站
  • 常用网站搜索引擎自己开网站需要什么