Linux 进程替换(exec函数)实现代码
# 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=/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("./myenv","myenv",NULL,env); execve("./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的结果图
下图是execle execve的结果图
- 看不过瘾?点击下面链接!
- PHP年月日的三级联动实例代码如何实现
- django框架怎么集成celery进行开发
- 动态数组C++实现方法详解
- java存储以及java对象创建的流程
- java线程池获取运行线程数并控制线程启动速度的方法
- Java 虚拟机(JVM)之基本概念详解