exec族函式總結

2021-07-09 11:45:18 字數 1163 閱讀 2937

1> execve為系統呼叫  其他的都是封裝的函式

l:引數列表   p:在環境變數path中尋找   v:引數陣列   e:替換環境變數列表

返回值:函式出錯 返回0   否則不反回(原來的使用者區已經被替換  只留下pcb所以沒有返回的地方)

exec族函式只替換使用者區  但是對核心區的pcb也有一定的影響(詳見 apue3 p201頁)

2> 對檔案描述符的影響

若開啟檔案時指定了fd_cloexec,則呼叫exec族函式時關閉這個檔案描述符否則此檔案描述符是開啟的

posix.1明確要求執行exec時關閉開啟的目錄

3>

#include

#include

#include

pro1:

char *env_init = ;

int main()

return 0;

}pro2:

extern char **environ;

int main()

return 0;

}用pro2來替換pro1  執行結果

wuliande@localhost 1]$ mytest1

user=unknownpath=/tmp/

返回我們設定的環境變數

直接執行 pro1

hostname=localhost.localdomainselinux_role_requested=term=term=linuxshell=/bin/bashhshell=/bin/bashhistsize=10histsize=1000ssh_client=1ssh_client=192.168.0.104 selinux_use_current_rangqtdir=/usr/lib/qt-3.3qqtinc=/usr/lib/qt-3.3/ssh_tty=/dev/pts/0ususer=wuliandels_colls_colors=rs=0:di=0mail=/var/spool/mapath=/usr/lib/qt-pwd=/home/wulianlang=zh_cn.utf-selinux_level_ssh_askpass=/histcontrol=shlvl=1homhome=/homelogname=wqtlib=/ucvs_rshssh_colessog_br_=/ol[wuliande@localhost 1]$ 

返回了使用者的環境變數

exec函式族筆記

include extern char environ int execl const char path,const char arg,int execv const char path,char const argv int execle const char path,const char a...

exec函式族小結

本人最近了解了關於exec函式族相關的知識,在此進行一下總結。fork函式是用於建立乙個子程序,該子程序幾乎是父程序的副本。而當我們希望子程序去執行另外的程式時,exec函式族就提供了乙個在程序中啟動另乙個程式執行的方法。它可以根據指定的檔名或目錄名找到可執行檔案 這裡的可執行檔案既可以是二進位制檔...

程序 exec函式族

一 exec函式族 通過呼叫exec函式族實現讓父子程序執行不同的程式,父程序不會受影響。exec函式族,就是以exec為開頭的函式,比如execl函式 execlp函式等,所以稱它為exec函式族。l list 命令列引數列表 p path 搜尋file時的使用的path變數 v vector向量...