Linux 進程替換(exec函數(shù))實現(xiàn)代碼
更新時間:2017年05月22日 14:22:39 投稿:lqh
這篇文章主要介紹了Linux 進程替換(exec函數(shù))實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
Linux 進程替換(exec函數(shù))實現(xiàn)代碼
# 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\n"); 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\n"); //exec成功的話不執(zhí)行此語句 exit(1); } else { pid_t ret=waitpid(id, NULL,0); if(ret>0) { printf("father wait success\n"); } else{ printf("child quit not normal\n"); } } return 0; }
下圖就是execl execlp execv execvp的結(jié)果圖
下圖是execle execve的結(jié)果圖
感謝閱讀,希望能幫助到大家,謝謝大家對對本知道支持!
相關(guān)文章
詳解Linux下的sudo及其配置文件/etc/sudoers的詳細配置
這篇文章主要介紹了詳解Linux下的sudo及其配置文件/etc/sudoers的詳細配置的相關(guān)資料,需要的朋友可以參考下2017-05-05linux每天定時備份數(shù)據(jù)庫并刪除十天前數(shù)據(jù)詳細步驟
每天定時備份數(shù)據(jù)庫需要用到Linux的定時任務(wù),利用Linux的crondtab 命令。下面通過本文給大家?guī)砹薼inux每天定時備份數(shù)據(jù)庫并刪除十天前數(shù)據(jù)詳細步驟,感興趣的朋友一起看看吧2018-06-06Shell實現(xiàn)識別物理cpu個數(shù)、核心數(shù)
這篇文章主要介紹了Shell實現(xiàn)識別物理cpu個數(shù)、核心數(shù),本文還介紹了判斷是否為超線程的功能,需要的朋友可以參考下2014-12-12