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

做网站的功能结构布局seo搜索优化费用

做网站的功能结构布局,seo搜索优化费用,建设网证书查询平台免费,南充房管局网站查询房产文章目录 一、进程程序替换(一)概念(二)为什么程序替换(三)程序替换的原理(四)如何进行程序替换1. execl2. 引入进程创建——子进程执行程序替换,会不会影响父进程呢? &…

文章目录

  • 一、进程程序替换
    • (一)概念
    • (二)为什么程序替换
    • (三)程序替换的原理
    • (四)如何进行程序替换
      • 1. execl
      • 2. 引入进程创建——子进程执行程序替换,会不会影响父进程呢?
    • (五)大量的测试各种不同的接口
      • 1.命名理解 (带v和带l的)
      • 2.记忆技巧
      • 3.带e和带p
    • (六)具体接口说明
      • 1.execv
      • 2.execlp
      • 3.execvp
      • 4.execle
  • 二、模拟实现shell
  • 三、内建命令——以chdir为例

一、进程程序替换

(一)概念

子进程执行的是父进程的代码片段,如果我们想让创建出来的子进程,执行全新的程序呢?

需要用到:进程的程序替换!

(二)为什么程序替换

我们一般在服务器设计(linux编程)的时候,往往需要子进程干两件种类事情!

  1. 让子进程执行父进程的代码片段(服务器代码)
  2. 让子进程执行磁盘中一个全新的程序(shell,想让客户端执行对应的程序,通过我们的进程,执行其他人写的进程代码等等),c/c++ ->c/c++/Python/Shell/Php/Java…

(三)程序替换的原理

  1. 将磁盘中的程序,加载入内存结构
  2. 重新建立页表映射,谁执行程序替换,就重新建立谁的映射(子进程)

效果:让我们的父进程和子进程彻底分离,并让子进程执行一个全新的程序!

在这里插入图片描述

这个过程有没有创建新的进程呢?

没有,子进程的PCB等结构并未改变,只是改变的页表映射关系。

程序替换成功后,运行完新程序,则程序直接退出;程序替换成功后,原进程没有退出,使用原进程运行新程序

我们只能调用接口,为什么呢?

因为这个过程实际上是把数据从一个硬件搬到另一个硬件的操作,这个操作只能由OS操作系统完成

(四)如何进行程序替换

man execl 查看进行程序替换的函数:
我们如果要执行一个全新的程序,我们需要做几件事情呢?

1.程序本质就是一个磁盘上的文件,所以我们需要先找到这个程序在哪里
2.程序可能携带选项进行执行(也可以不携带),然后告诉OS,我要怎么执行这个程序?(要不要带选项)

命令行怎么写(ls -l -a), 这个参数就怎么填"ls",“-l”,“-a”,最后必须是NULL,标识参数传递完毕[如何执行程序的]
00

 #include <unistd.h>extern char **environ;int 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 execvpe(const char *file, char *const argv[],char *const envp[]);

1. execl

makefile

myexec:myexec.cg++ -o $@ $^ -std=c++11 
.PHONY:clean
clean:rm -f myexec

myexec.c

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<assert.h>
#include<sys/types.h>
#include<sys/wait.h>int main(int argc,char *argv[]) {printf("process is running...\n");pid_t id  = fork();assert(id != -1);if (id == 0) {sleep(1);printf("我是一个进程,我的pid是:%d\n",getpid());// 执行ls -l -a 命令//execl("/usr/bin/ls","ls","-l","-a",NULL); // 这里有两个ls, 重复吗?不重复,一个是告诉系统我要执行谁?一个是告诉系统,我想怎么执行// 执行top命令execl("/usr/bin/top","top",NULL);               printf("我执行完毕了,我的pid是:%d\n",getpid());      // 执行完以上的代码,我们发现一个问题!!// 最后一句代码为什么没有被打印出来呢!!!}return 0;
}

在这里插入图片描述
因为进程一旦替换成功,是将当前进程的代码和数据全部替换了!!!

后面的printf是代码吗??有没有被替换呢??当然,已经早就被替换了!!该代码不存在了!!

所以这个程序替换函数,用不用判断返回值?为什么?

答:不用判断返回值,因为只要成功了,就不会有返回值execl,一旦替换成功,是将当前进程的所有代码和数据全部替换了,execl就直接执行ls命令的代码去了。。而失败的时候,必然会继续向后执行!!最多通过返回值得到什么原因导致的替换失败!

2. 引入进程创建——子进程执行程序替换,会不会影响父进程呢?

子进程执行程序替换,会不会影响父进程呢? ?

不会,因为进程具有独立性。
为什么,如何做到的? ?数据层面发生写时拷贝!当程序替换的时候,我们可以理解成为:代码和数据都发生了写时拷贝完成父子的分离!

(五)大量的测试各种不同的接口

1.命名理解 (带v和带l的)

这些函数原型看起来很容易混,但只要掌握了规律就很好记。l(list) : 表示参数采用列表v(vector) : 参数用数组p(path) : 有p自动搜索环境变量PATHe(env) : 表示自己维护环境变量

2.记忆技巧

execl结尾 l 为list,列表传参——>可变参数包,一个一个传。execv结尾 v 为vector,数组传参——>传的是指针数组。

3.带e和带p

带e的都是可以传环境变量的(execle,execvpe)但是会覆盖系统原有的环境变量,把自己传的环境变量交给进程;
不带e是默认继承系统的环境变量;带p的都是可以自带路径的,直接传命令名称即可(execlp,execvp,execvpe)

(六)具体接口说明

1.execv

int execv(const char *path, char *const argv[]);        

path 依然是程序的路径,参数 argv[] 是存着要实现指令的指针数组
在这里插入图片描述

char *const argv_[] = {"ls","-a","-l","--color=auto",NULL
};

2.execlp

int execlp(const char *file, const char *arg, ...);        带p的就传程序名即可file:要执行的程序。执行指令的时候,默认的搜索路径,在哪里搜索呢?在环境变量PATH
命名带p的,可以不带路径,只说出你要执行哪一个程序即可!execlp("ls""ls", "-a", "-1 "NULL)
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<assert.h>
#include<sys/types.h>
#include<sys/wait.h>int main(int argc,char *argv[]) {printf("process is running...\n");pid_t id  = fork();assert(id != -1);if (id == 0) {sleep(1);printf("我是一个进程,我的pid是:%d\n",getpid());//execl("/usr/bin/ls","ls","-l","-a",NULL); // 这里有两个ls, 重复吗?不重复,一个是告诉系统我要执行谁?一个是告诉系统,我想怎么执行// 执行top命令char *const argv_[]={(char*)"ls",(char*)"-a",(char*)"-l",NULL};//execl("/usr/bin/top","top",NULL);         execlp("ls","ls","-a","-l",NULL);//这里出现了两个ls,含义一样吗?不一样!exit(1);   //execvp("ls", argv_);printf("我执行完毕了,我的pid是:%d\n",getpid());      // 执行完以上的代码,我们发现一个问题!!// 最后一句代码为什么没有被打印出来呢!!!}int status = 0;int ret = waitpid(id,&status,0);if(ret == id){sleep(2);printf("父进程等待成功!\n");}return 0;
}

在这里插入图片描述

3.execvp

 int execvp(const char *file, char *const argv[]);
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<assert.h>
#include<sys/types.h>
#include<sys/wait.h>int main(int argc,char *argv[]) {printf("process is running...\n");pid_t id  = fork();assert(id != -1);if (id == 0) {sleep(1);printf("我是一个进程,我的pid是:%d\n",getpid());//execl("/usr/bin/ls","ls","-l","-a",NULL); // 这里有两个ls, 重复吗?不重复,一个是告诉系统我要执行谁?一个是告诉系统,我想怎么执行// 执行top命令char *const argv_[]={(char*)"ls",(char*)"-a",(char*)"-l",NULL};//execl("/usr/bin/top","top",NULL);         //execlp("ls","ls","-a","-l",NULL);//这里出现了两个ls,含义一样吗?不一样!exit(1);   execvp("ls", argv_);printf("我执行完毕了,我的pid是:%d\n",getpid());      // 执行完以上的代码,我们发现一个问题!!// 最后一句代码为什么没有被打印出来呢!!!}// 父进程int status = 0;int ret = waitpid(id,&status,0);if(ret == id){sleep(2);printf("父进程等待成功!\n");}return 0;
}

在这里插入图片描述

4.execle

int execle(const char *path, const char *arg,..., char * const envp[]);

这里的前几个接口都非常熟悉了,这里最后一个接口叫做环境变量。那么为什么要有这个接口呢?

说到环境变量之前我们先来看一下这个问题,我们刚刚提到过,进程替换可以让我们执行其他语言写的程序,那么我们怎么来执行呢?(我们使用execl 函数来调用)

我们现在的目标是想用我们写的myexec.c把mycmd.cpp调用起来,那么怎么来用呢?
myexec.c

我们当前使用的是绝对路径来调用我的mycmd程序!

当然我们也可以使用相对路径来调用。

相对路径调用——
makefile

.PHONY:all
all: mybin myexec
mybin:mybin.cg++ -o $@ $^ -std=c++11
myexec:myexec.cg++ -o $@ $^ -std=c++11
.PHONY:clean
clean:rm -f myexec mybin
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>int main()
{printf("我是一个进程,我的pid是:%d\n",getpid());pid_t id=fork(); if(id==0){//childprintf("我是子进程,我的pid是:%d\n",getpid());execl("./mycmd","mycmd",NULL);exit(1);}//一定是父进程int status=0;int ret=waitpid(id,&status,0);if(ret==id){sleep(2);printf("父进程等待成功!\n");}return 0;
}

在这里插入图片描述
为什么会有这么多接口?——因为要适配应用场景。

execve为什么是单独的?——实际上,只有 execve是系统调用,其他都是对系统接口的封装,最后都要调用到execve!
在这里插入图片描述

二、模拟实现shell

三、内建命令——以chdir为例


文章转载自:
http://dinncoastrologist.bkqw.cn
http://dinncopneumorrhagia.bkqw.cn
http://dinncoqualitatively.bkqw.cn
http://dinncotitanosaur.bkqw.cn
http://dinncowastery.bkqw.cn
http://dinncocentralia.bkqw.cn
http://dinncohepatosis.bkqw.cn
http://dinncosichuan.bkqw.cn
http://dinncowhipstall.bkqw.cn
http://dinncordram.bkqw.cn
http://dinncopentanol.bkqw.cn
http://dinncobudge.bkqw.cn
http://dinncopareu.bkqw.cn
http://dinncocanty.bkqw.cn
http://dinncooverpass.bkqw.cn
http://dinncoradius.bkqw.cn
http://dinncothrenody.bkqw.cn
http://dinncodivisibility.bkqw.cn
http://dinncoferial.bkqw.cn
http://dinncogarter.bkqw.cn
http://dinncopadouk.bkqw.cn
http://dinncoperspicacity.bkqw.cn
http://dinncohomonymic.bkqw.cn
http://dinncoescot.bkqw.cn
http://dinncoquatercentenary.bkqw.cn
http://dinncocribo.bkqw.cn
http://dinncovermont.bkqw.cn
http://dinncoforint.bkqw.cn
http://dinnconictation.bkqw.cn
http://dinncochirpily.bkqw.cn
http://dinncoverbiage.bkqw.cn
http://dinncoirremediable.bkqw.cn
http://dinncotrilling.bkqw.cn
http://dinncocesium.bkqw.cn
http://dinncointone.bkqw.cn
http://dinncoabomasum.bkqw.cn
http://dinncoprizefighting.bkqw.cn
http://dinncomisapplication.bkqw.cn
http://dinncoseventieth.bkqw.cn
http://dinncodens.bkqw.cn
http://dinncolettuce.bkqw.cn
http://dinncoenterograph.bkqw.cn
http://dinncosubseptate.bkqw.cn
http://dinncoboltoperated.bkqw.cn
http://dinncowran.bkqw.cn
http://dinncoinviolable.bkqw.cn
http://dinncomarina.bkqw.cn
http://dinncoordinary.bkqw.cn
http://dinncologographer.bkqw.cn
http://dinncofogger.bkqw.cn
http://dinncomorphosis.bkqw.cn
http://dinncocontroversy.bkqw.cn
http://dinncodude.bkqw.cn
http://dinncooxherd.bkqw.cn
http://dinncosiphonaceous.bkqw.cn
http://dinncosimbirsk.bkqw.cn
http://dinncoshilka.bkqw.cn
http://dinncohemophobia.bkqw.cn
http://dinncononcom.bkqw.cn
http://dinncoataractic.bkqw.cn
http://dinncowebfoot.bkqw.cn
http://dinncobedding.bkqw.cn
http://dinncoencyclopaedia.bkqw.cn
http://dinncoretrieve.bkqw.cn
http://dinncolynchpin.bkqw.cn
http://dinncochalky.bkqw.cn
http://dinncomacumba.bkqw.cn
http://dinncofumaroyl.bkqw.cn
http://dinncoeo.bkqw.cn
http://dinncobilsted.bkqw.cn
http://dinncorocketman.bkqw.cn
http://dinncopugree.bkqw.cn
http://dinncostan.bkqw.cn
http://dinncokinetophonograph.bkqw.cn
http://dinncoapocopate.bkqw.cn
http://dinncocenturial.bkqw.cn
http://dinncopodsolise.bkqw.cn
http://dinncogasometry.bkqw.cn
http://dinncocavy.bkqw.cn
http://dinncopolytropic.bkqw.cn
http://dinncocloze.bkqw.cn
http://dinncoemplace.bkqw.cn
http://dinncomacroaggregate.bkqw.cn
http://dinncocovenant.bkqw.cn
http://dinncotelemetry.bkqw.cn
http://dinncoconsiderate.bkqw.cn
http://dinncoactinodermatitis.bkqw.cn
http://dinncorosella.bkqw.cn
http://dinncotrustingly.bkqw.cn
http://dinncowailful.bkqw.cn
http://dinncodeflationist.bkqw.cn
http://dinncocrazed.bkqw.cn
http://dinncoplankton.bkqw.cn
http://dinncograssfinch.bkqw.cn
http://dinncomaryolatry.bkqw.cn
http://dinncocccs.bkqw.cn
http://dinncopalpitate.bkqw.cn
http://dinncosacra.bkqw.cn
http://dinncoacutilingual.bkqw.cn
http://dinncoscowly.bkqw.cn
http://www.dinnco.com/news/94281.html

相关文章:

  • 安庆市住房和建设厅网站windows优化大师在哪里
  • 网站的全栈建设霸榜seo
  • 网站开发 哪些文档seo虚拟外链
  • 建网站哪家好新闻seo教程 seo之家
  • 松原网站建设哪家专业百度非企渠道开户
  • 企业网站的开发营销型网站案例
  • 关键词库在网站上怎么体现网络平台推广
  • 什么网站百度收录快seocms
  • 采购网站建设推广赚佣金的平台
  • 门户网站开发难点肇庆疫情最新情况
  • 网站是可以做的吗php开源建站系统
  • 长沙公司网站设计报价目前较好的crm系统
  • 网站服务器内部错误是怎么回事100大看免费行情的软件
  • 马克斯网站建设谷歌google中文登录入口
  • wordpress 书籍主题百度seo排名优化软件化
  • 北京做网站的公司排行搜索引擎优化服务公司哪家好
  • 做外贸最适合的网站系统国内最新新闻事件
  • 如何做网站实名认证免费的html网站
  • 做网页靠哪个网站赚钱电商网站前端页面内容编写
  • 网站如何建设手机版徐州网站设计
  • 网络规划设计师科目分类免费seo教程分享
  • 常州网站建设效果博客网站
  • 腾讯云服务器搭建网站成都网络推广外包
  • 二手网站需求建设分析营销型网站推广方案
  • 微博网站认证 备案名称百度小程序入口
  • 河源哪有做网站全网搜索关键词查询
  • 泰安东平县建设局网站专业做网站设计
  • 宣讲家网站 政治建设网站推广途径和推广要点有哪些?
  • 建设企业网站开发公司北京百度推广优化公司
  • 网站维护需要多长时间seo云优化是什么意思