当前位置: 首页 » 产品 » 微商货源 » 正文

Linux进程替换(exec函数实现代码

放大字体  缩小字体 发布日期: 2024-09-27 23:28   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:12
核心提示:# includestdio.h#includestdlib.h#includeunistd.h#includefcntl.h#includesys/types.h#includesys/stat.h#includestring.hint

# include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<fcntl.h> #include<sys/types.h> #include<sys/stat.h> #include<string.h> int main() { pid_t id=fork(); if(id==0) { printf("child is running "); sleep(1); char* env[]={"MYENV=http://www.3lian.com/A/B/C/D/AAAA",NULL}; char* argv[]={"ls","-l","-n","-i",NULL}; // execl("/bin/ls","ls","-l","-n","-i",NULL); // execlp("ls","ls","-l","-n","-i",NULL); // execv("/bin/ls",argv); // execvp("ls",argv); // execle("http://www.jsgho.com/help/fwq/myenv","myenv",NULL,env); execve("http://www.jsgho.com/help/fwq/myenv",argv,env); printf("child id done "); //exec成功的话不执行此语句 exit(1); } else { pid_t ret=waitpid(id, NULL,0); if(ret>0) { printf("father wait success "); } else{ printf("child quit not normal "); } } return 0; }

下图就是execl execlp execv execvp的结果图

Linux进程替换(exec函数实现代码 三联

下图是execle execve的结果图

Linux进程替换(exec函数实现代码

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站