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

现在还做自适应网站百度推广效果

现在还做自适应网站,百度推广效果,php 企业网站 后台图片上传,wordpress添加视频概念 当我们使用fork时,会创建一个子进程来给我们执行代码,但是子进程执行的也是父进程的代码,我们再写代码的时候,往往是需要执行其它代码,所以当其它程序的代码替换到自己的程序中执行,这种行为叫&#…

概念

当我们使用fork时,会创建一个子进程来给我们执行代码,但是子进程执行的也是父进程的代码,我们再写代码的时候,往往是需要执行其它代码,所以当其它程序的代码替换到自己的程序中执行,这种行为叫,进程的替换

使用进程的替换我们往往需要使用exec类型函数来进行

让我们来查看一下exec的类型函数有哪些

man exec //查看exec函数有哪些

exec函数有六种,让我们来分别讲解用途。

execl

int execl(const char *pathname, const char *arg, .../* (char  *) NULL */);

参数讲解 :

pathname:用于指定可执行程序的绝对路径

arg:用于指定可执行程序

...:是一个多参数类型,用于指定运行可执行程序的执行方式。

NULL:execl函数后面需要加NULL

我们来举几个例子来实验一下

创建两个文件,text3.c和text2.c

text3.c

#include<stdio.h>
#include<unistd.h>
int main()
{printf("execl start text3....\n");execl("/root/working8/text2","text2",NULL);printf("text3 to be action\n");return 0;
}

text2.c 

#include<stdio.h>
int main()
{printf("text2 to be action\n");
}

当前文件路径 

/root/working8

执行text3.c的可执行文件

 

 我们看到,execl,替换代码后运行的是text2的代码,所以execl函数将代码替换了

替换代码是不是又创建了一个进程呢,我们通过getpid函数来验证一下

text3.c代码

#include<stdio.h>
#include<unistd.h>
int main()
{printf("execl start text3....\n");printf("PID:%d\n",getpid());execl("/root/working8/text2","text2",NULL);printf("text3 to be action\n");return 0;
}

text2.c代码

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{printf("text2 to be action\n");printf("PID:%d\n",getpid());
}

运行结果

 

上面的PID和下面的PID相同,说明execl函数是将text2.c的代码复制到了text3.c中,而不是新创建了一个进程。 

execlp 

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

这里的file与上面的PATH有所不同,file是用来指定环境变量中的文件名,而PATH是用来指定可执行文件的绝对路径 ,其它的与上面的execl相同

 我们来用代码解释一下

#include<stdio.h>
#include<unistd.h>
int main()
{printf("execl start text3....\n");execlp("ls","ls","-l","-a",NULL);printf("text3 to be action\n");return 0;
}

因为ls存在与环境变量中,所以我们可以直接指定。

执行结果 :

我们将text2可执行文件放入PATH中看看能不能直接执行

PATH=$PATH:/root/working8

我们将当前路径添加到PATH环境变量中

更改text3.c代码

#include<stdio.h>
#include<unistd.h>
int main()
{printf("execl start text3....\n");execlp("text2","text2",NULL);printf("text3 to be action\n");return 0;
}

text2.c代码

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{printf("text2 to be action\n");printf("PID:%d\n",getpid());
}

执行结果

 

 我们可以发现execlp后面执行的是text2.c的代码

execle

execle通常用来更改环境变量表

int execle(const char *pathname, const char *arg, .../*, (char *) NULL, char *const envp[] */);

 其中NULL的后面还要增加一个char *const envp指针数组,这个指针数组就用用来更改环境变量的表

当进程替换之后,环境变量会继续使用之前的。

我们来用两组代码测试一下

text3.c

#include<stdio.h>
#include<unistd.h>
int main()
{printf("execl start text3....\n");execl("/root/working8/text2","text2",NULL);return 0;
}

text2.c

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main(int argc,char*argv[],char * env[])
{for(int i=0;i<20;i++){printf("[%d]:%s\n",i,env[i]);}
}

运行结果

 

我们可以看到进程还是用了替换之前的环境变量 

 我们使用execle随便更改几个环境变量

 更改text3.c代码

#include<stdio.h>
#include<unistd.h>
int main()
{printf("execl start text3....\n");char* const ch[]={"A=aaa","B=bbb",NULL};execle("/root/working8/text2","text2",NULL,ch);return 0;
}

再次运行text3.c的可执行文件

运行结果

 

 以上是execl的进程替换操作

execle和execl是要操作文件绝对路径的,而execle可以更改进程当前的环境变量。

execlp需要操作环境变量,操作PATH中的环境变量

execv系列

int execv(const char *pathname, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execvpe(const char *file, char *const argv[],char *const envp[]);

 char *const argv[]:是一个数组,里面包含了需要执行的文件,和文件执行的方式

file:和上面是一样的意思,文件名,此文件需要在环境变量表中

envp:用于修改进程的环境变量

我们来演示一下char*const argv[]的作用,其它的函数参数是大同小异的,不同的是我们不需要在函数参数的最末尾加NULL但是我们需要在数组的最末尾加NULL

代码如下

#include<stdio.h>
#include<unistd.h>
int main()
{printf("execl start text3....\n");char*const ch[]={"ls","-l","-a",NULL};execv("/usr/bin/ls",ch);return 0;
}

执行结果如下

 

 

p用于指定文件,在PATH环境变量表中查可执行文件
l全名list,函数参数以链表的形式传入函数
vvector,函数参数以数组的方式传入函数
eenv,环境变量,可以修改进程的环境变量

汇总一下六个进程替代的函数

int execl(const char *pathname, const char *arg, .../* (char  *) NULL */);
int execlp(const char *file, const char *arg, ... /* (char  *) NULL */);
int execle(const char *pathname, const char *arg, .../*, (char *) NULL, char *const envp[] */);
int execv(const char *pathname, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execvpe(const char *file, char *const argv[],char *const envp[]);

 

 

 

 

 

 

 

 

 

 

 

http://www.dtcms.com/wzjs/398625.html

相关文章:

  • 社交网站是怎么做的指数型基金
  • 做义工的同城网站百度网页收录
  • 做医疗护具网站中国搜索引擎市场份额
  • 网站推广到海外怎么做bt磁力在线种子搜索神器下载
  • 做网站怎么自定义背景图片seo学校培训
  • 网站制作公司咨询热线网站关键词优化系统
  • 微信、网站提成方案点做爱站网站长seo综合查询
  • 企多维企业查询官网鸡西seo顾问
  • 哪个网站做的win10系统墨猴seo排名公司
  • 做健康食品的网站企业员工培训总结
  • yii2框架做的网站有哪些建立网站的基本流程
  • 仿站网站建设自媒体怎么做
  • 建筑师网站品牌策划方案ppt
  • asp网站压缩2022新闻热点10条
  • 安徽网站开发费用seo怎么提升关键词的排名
  • 网站开发技术总结原画培训机构哪里好
  • 如何优化营销型企业网站如何在百度做免费推广产品
  • 24小时学会网站建设外贸推广是做什么的
  • 网站建设用户调查问卷免费seo排名软件
  • 贵阳网站建设培训学校响应式模版移动优化
  • 什么网站可以在图片上做超链接整站优化快速排名
  • 常州免费建站seo服务外包公司
  • 开发人员工具百度seo快速排名
  • 手机做任务赚钱网站服务营销的概念
  • 下载wix做的网站靠谱的seo收费
  • 如何在youtube找人做视频网站百度网址大全下载
  • 做网站建设公司属于诈骗嘛seo经验是什么
  • 做网站明细范文关键词快速优化排名软件
  • 怎么做网页机器人seo神器
  • 地产网站建设旺道seo优化