?
進程調用exec函數族執行某個程序
進程當前程序被執行程序替換
讓父子進程執行不同的程序
父進程創建子進程
子進程調用exec函數族·
父進程不受影響
?
#include<unistd.h>
int execl(const char *path, const char *arg, ...)
int execlp(const char *file, const char *arg,...)
?
成功則執行指定程序 失敗則返回EOF
path 執行的程序的名稱 包含路徑
arg.... 傳遞給程序的參數
file 執行的程序的名稱 不含路徑 需要在PATH環境變量中查找
?
#include<unistd.h>
int execv(const char *path, char *const argv[],...)
int execvp(const char *file, char *const srgv[],....)
成功執行指定程序 失敗返回EOF
arg....封裝成指針數組的形式
?
Ps:char *arg[]= {"ls","-a", "-l", "/etc", NULL};
if(execv("/bin/ls", arg) < 0)
{
perror("execv");
}
?
#include <stdlib.h>
int system(const char *command)
成功返回command命令的返回值 失敗返回EOF
函數的實現過程 是 先創建一個子進程 然后system()在子進程中執行命令 父進程需要等待子進程執行完之后才能繼續執行