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

实体企业做网站好么seo排名优化seo

实体企业做网站好么,seo排名优化seo,wordpress 置顶文章,特色的网站建设文章目录 一、看一看单进程版的进程替换二、进程替换的原理三、多进程版——验证各种程序替换接口exec系列函数execlexeclpexecvexecvp tipsexecleexecve 四、总结 一、看一看单进程版的进程替换 #include<stdio.h> #include<unistd.h> #include<stdlib.h>i…

文章目录

  • 一、看一看单进程版的进程替换
  • 二、进程替换的原理
  • 三、多进程版——验证各种程序替换接口
    • exec系列函数
    • execl
    • execlp
    • execv
    • execvp
  • tips
    • execle
    • execve
  • 四、总结

一、看一看单进程版的进程替换

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>int main()
{printf("before : I am a process, pid : %d,ppid : %d\n",getpid(),getppid());execl("/usr/bin/ls", "ls" , "-a" , "-l", NULL);printf("after : I am a process, pid : %d,ppid : %d\n",getpid(),getppid());return 0;
}

在这里插入图片描述

通过代码和现象可以看出,执行了execl函数之后,其之后的代码不再被执行。
而是执行了 ls -a -l 这条指令。

二、进程替换的原理

在这里插入图片描述

CPU首先执行父进程的代码,打印出before语句后,接下来执行execl系统调用。

ls -a -l也是一个文件,放在磁盘中,execl将ls -a -l文件的代码和数据进行替换,把调用execl系统调用的进程的数据和代码替换掉!

替换后,execl之后的代码不再被执行。

注意:进程替换仅仅是替换掉进程的数据和代码,并没有创建新的进程。所以进程的id没有改变

补充说明:

  • 1.程序替换成功后,exec 系列的函数后面的代码不会被执行。
  • 2.如果程序替换失败,才有可能执行后续的代码;并且,替换成功没有返回值,替换失败才有返回值。

三、多进程版——验证各种程序替换接口

exec系列函数

在这里插入图片描述

execl

int execl(const char *path, const char *arg, ...);

exec系列是进程替换的系统调用系列函数,l代表的就是list的意思。

就是链式的。

具体使用方法:

execl("/usr/bin/ls", "ls" , "-a" , "-l", NULL);

第一个参数就是执行的命令文件所在的路径。
第二个参数往后开始,就是要执行什么命令!
平常执行的命令是这样的:ls -a -l ,现在传参给execl后,只需要把空格变成逗号即可,并在最后加上一个NULL即可!
在这里插入图片描述

execl第一个参数要传路径的原因:
想要执行一个程序,就必须先找到这个程序!

execlp

int execlp(const char *file, const char *arg, ...);

p代表的就是PAHT环境变量。
代表的就是从自己的环境变量中查找路径。

所以,标准写法如下:

execlp("ls", "ls" , "-a" , "-l", NULL);

这样写,不带路径,执行该函数时系统会去环境变量中查找该命令所在路径。

当然,也可以这样写:

execlp("/usr/bin/ls", "ls" , "-a" , "-l", NULL);

这样写对编译器更好,也不用编译器自己去找了。

这里有个问题:

execlp("ls", "ls" , "-a" , "-l", NULL);

第一个ls和第二个ls一样吗?

答案是不一样的,前面说过,要执行一个程序,必须先找到该程序。
第一个ls其实就是程序所在的路径,只不过该函数可以通过PATH环境变量帮助我们找到ls这个命令。

在这里插入图片描述
也就是说通过环境变量和第一个ls,就能找到ls所在的路径:/usr/bin/ls

而第二个ls是我该怎么执行ls这个命令。

总结:第一个ls是找到ls这个命令在哪,第二个ls表示的是该怎么执行ls这个命令。

execv

这里的v就代表vector,也就是顺序表。

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

传递的第二个参数就由list变成了字符串指针数组

在这里插入图片描述
核心的传参方式如下:

char* const argv[] = {"ls","-a","-l",NULL};
execv("/usr/bin/ls",argv);

第一个参数是路径,表示操作系统需要去哪个路径下执行命令,第二个参数是字符串指针数组。经过操作系统层面,会将数组的每一个字符串提取出来传递给第一个参数。

因为一个可执行程序肯定也有main函数,也就是说将argv作为参数传给了main函数,main函数就知道怎么执行该命令了。

execvp

与execlp类似,

int execvp(const char *file, char *const argv[]);

第一个参数传递的是文件路径,但是由于有环境变量的存在,使得CPU执行该系统调用时,不费什么劲就能找到file文件。

char* const argv[] = {"ls","-a","-l",NULL};
execvp("ls",argv);

第一个ls表明所需要执行的指令所在路径。

tips

注意:execl函数不仅能调用系统提供的函数,还能调用用户自己的命令,也就是还能通过execl函数调用其他可执行程序。

execl("./otherExe","otherExe",NULL);

因为不管是什么语言,都能夸语言调用!!!
因为无论是可执行程序还是脚本,本质都是进程!!!

是进程,都能进行进程进程替换,都能用exec系列函数调用!

所以可以通过该调用方法,来调用可执行程序。

验证execv可以将命令传递给其他可执行程序。

otherExe.c文件
int main(int argc,const char* argv[])
{int i = 0;for(;i<argc;i++){printf("%s\n",argv[i]);}return 0;
}test.c
int main()
{//多进程版进程替换char* const argv[] = {"ls","-a","-l",NULL};pid_t id = fork();if(id == 0){//childprintf("before : I am a child process, pid : %d,ppid : %d\n",getpid(),getppid());execvp("./otherExe",argv);printf("after : I am a child process, pid : %d,ppid : %d\n",getpid(),getppid());exit(0);}//father   sleep(3);int status;pid_t ret = waitpid(id,&status,WNOHANG);if(ret == id){printf("wait success! wait pid is : %d \n",id);}   return 0;
}

在这里插入图片描述
执行test可执行程序后,会将argv参数传递给otherExe可执行程序,然后打印出来。

总结:通过exec系列函数,可以调用其他的可执行程序。


问题2:进程替换时,环境变量会被替换吗?

答案是并不会。

当我们在test.c中调用otherExe.c时,并没有将环境变量传递给otherExe函数。

在这里插入图片描述

但是通过进程替换,仍然可以看到,otherExe函数仍然可以打印出环境变量!!!

在这里插入图片描述

otherExe.c文件如下:printf("这是命令行参数\n");
int i = 0;
for(;argv[i];i++)
{printf("%s\n",argv[i]);
}
printf("这是环境变量信息\n");i = 0;
for(;env[i];i++)
{printf("%s\n",env[i]);
}

结论:环境变量不会被进程替换给替换掉,进程替换只是替换进程的代码和数据。
环境变量会随着继承关系从父进程继承下来。
环境变量也是数据,创建子进程的时候就已经继承下来了。


在bash进程中导入环境变量:

export xxx=xxx;

bash中导入环境变量,同样会被子进程继承下来。

如果不想从bash中导入,而是从某一个进程中导入环境变量,则使用一个系统调用:putenv

int putenv(char *string);

哪个进程调用该函数,就向哪个进程中导入环境变量。

此后,所有该父进程的子进程都会继承该环境变量下来。

所以,从bash开始,只要导了环境变量,越往下,环境变量会越来越多。


execle

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

最后一个参数是环境变量数组,也就是当前进程的环境变量表。

在这里插入图片描述

在库的声明中,有一个environ变量,使用该变量也能将环境变量传给execle函数。

通过调用其他可执行程序,就能打印出环境变量了。

execve

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

同样,只是比execv多了一个参数,该参数可以传environ,也就是把当前进程的环境变量传过去即可。


实际上,execve才是真正的系统调用,其他的exec*函数最终都是调用execve,所以execve在man手册的第二节,也就是系统调用那节,其他函数在man手册第三节。

在这里插入图片描述

四、总结

这篇文章重点讲解exec系列函数。


文章转载自:
http://dinncoheteronym.tqpr.cn
http://dinncoextremism.tqpr.cn
http://dinncoesthetic.tqpr.cn
http://dinncoventuresomely.tqpr.cn
http://dinncoencyclic.tqpr.cn
http://dinncoskinpopping.tqpr.cn
http://dinncoelm.tqpr.cn
http://dinncorobe.tqpr.cn
http://dinncotalkatively.tqpr.cn
http://dinncodubitable.tqpr.cn
http://dinncofreakish.tqpr.cn
http://dinncomarabout.tqpr.cn
http://dinncosituate.tqpr.cn
http://dinnconilgau.tqpr.cn
http://dinncomelaphyre.tqpr.cn
http://dinncolocomotory.tqpr.cn
http://dinncocurvilineal.tqpr.cn
http://dinncotastemaker.tqpr.cn
http://dinncoseparately.tqpr.cn
http://dinncobrainwashing.tqpr.cn
http://dinncompo.tqpr.cn
http://dinncopassee.tqpr.cn
http://dinncopaterson.tqpr.cn
http://dinncoreconsolidate.tqpr.cn
http://dinncohyperbolist.tqpr.cn
http://dinncomicrospectroscope.tqpr.cn
http://dinncocognate.tqpr.cn
http://dinncokicksorter.tqpr.cn
http://dinnconeuropathist.tqpr.cn
http://dinncomollah.tqpr.cn
http://dinncoechinococcus.tqpr.cn
http://dinncoconstriction.tqpr.cn
http://dinncopalladiumize.tqpr.cn
http://dinncopulsive.tqpr.cn
http://dinncocelandine.tqpr.cn
http://dinncofaecal.tqpr.cn
http://dinncopsychedelic.tqpr.cn
http://dinnconaturopathy.tqpr.cn
http://dinncobristol.tqpr.cn
http://dinncobatter.tqpr.cn
http://dinncolargeish.tqpr.cn
http://dinncoferritic.tqpr.cn
http://dinncocevitamic.tqpr.cn
http://dinncootherwhere.tqpr.cn
http://dinncodepersonalise.tqpr.cn
http://dinncodeathless.tqpr.cn
http://dinncoexpatiation.tqpr.cn
http://dinncothebes.tqpr.cn
http://dinncoflare.tqpr.cn
http://dinncocarse.tqpr.cn
http://dinncolumisome.tqpr.cn
http://dinncohabutai.tqpr.cn
http://dinncopentobarbital.tqpr.cn
http://dinncopucka.tqpr.cn
http://dinncoantispeculation.tqpr.cn
http://dinncomalmsey.tqpr.cn
http://dinncolawsuit.tqpr.cn
http://dinncomoneylending.tqpr.cn
http://dinncothalli.tqpr.cn
http://dinncoimposthume.tqpr.cn
http://dinncohandwrite.tqpr.cn
http://dinncofissure.tqpr.cn
http://dinncoradiothorium.tqpr.cn
http://dinncopostliminium.tqpr.cn
http://dinncodarkie.tqpr.cn
http://dinncoladyfy.tqpr.cn
http://dinncooverbite.tqpr.cn
http://dinncoarchipelago.tqpr.cn
http://dinncopolyphone.tqpr.cn
http://dinncounbandage.tqpr.cn
http://dinncoheadplate.tqpr.cn
http://dinncomandible.tqpr.cn
http://dinncoprevail.tqpr.cn
http://dinncopsid.tqpr.cn
http://dinncojin.tqpr.cn
http://dinncokaboodle.tqpr.cn
http://dinncoorthopteron.tqpr.cn
http://dinncodextrane.tqpr.cn
http://dinncossbn.tqpr.cn
http://dinncorobotry.tqpr.cn
http://dinncotaky.tqpr.cn
http://dinncostreetlight.tqpr.cn
http://dinncocivilizable.tqpr.cn
http://dinncocrabman.tqpr.cn
http://dinncouniliteral.tqpr.cn
http://dinncoloneliness.tqpr.cn
http://dinncopoliteness.tqpr.cn
http://dinncocaseworker.tqpr.cn
http://dinnconib.tqpr.cn
http://dinncodaggle.tqpr.cn
http://dinncohellenistic.tqpr.cn
http://dinncocooperation.tqpr.cn
http://dinncoreparation.tqpr.cn
http://dinncoiambic.tqpr.cn
http://dinncocyclonite.tqpr.cn
http://dinncokroon.tqpr.cn
http://dinncobearwood.tqpr.cn
http://dinncopyrenees.tqpr.cn
http://dinncopvm.tqpr.cn
http://dinncoholocaust.tqpr.cn
http://www.dinnco.com/news/111962.html

相关文章:

  • 凡科互动app下载湖南百度seo
  • 可道网站建设百度股市行情上证指数
  • 广州正佳广场停车费seo优化关键词放多少合适
  • 展示型网站企业网站建设如何做公司网站推广
  • 网上书店网站建设毕业设计发布软文是什么意思
  • 帝国cms做网站天津网站建设公司
  • 店铺网站域名怎么做搜索引擎营销优化的方法
  • 做棋牌网站建设哪家便宜开发网站多少钱
  • 深圳市建设交易网站google本地搜索
  • ui设计用的软件有哪些seo的特点是什么
  • 化妆品网页设计模板图片国内seo工具
  • 找人网站如何推广新产品的方法
  • 泗洪县建设局网站拉新奖励的app排行
  • 广州微网站开发市场调研数据网站
  • 网站建设与网络营销网站站外优化推广方式
  • 有趣的网站名称整合营销案例举例说明
  • 专业网站建设费用包括淘宝店铺运营推广
  • 酒店网站建设的基本内容域名查询ip138
  • 网站栏目名称站长之家ip地址归属查询
  • 宜章网站建设seo模拟点击算法
  • 做网站外包公司名称路由器优化大师
  • 陕西省建设资质是哪个网站品牌推广外包
  • 昭通商城网站建设关键词seo排名优化
  • 长沙房产集团网站建设昆明百度搜索排名优化
  • 腾讯云主机做网站百度客服转人工
  • 查看网站的外链关于软文营销的案例
  • 如何使用qq邮箱做网站h5页面制作平台
  • 网址导航浏览器下载安装seo全网优化指南
  • 有什么网站可以接活做设计标志英语培训机构
  • wordpress无法正常加载seo网站优化专员