?? exec.2
字號:
.TH EXEC 2 .SH NAMEexecl, execv, execle, execve, execlp, execvp, exec, exece, environ \- execute a file.SH SYNOPSIS.B execl(name, arg0, arg1, ..., argn, 0).br.B char *name, *arg0, *arg1, ..., *argn;.PP.B execv(name, argv).br.B char *name, *argv[ ];.PP.B "execle(name, arg0, arg1, ..., argn, 0, envp).br.B "char *name, *arg0, *arg1, ..., *argn, *envp[ ];.PP.B execve(name, argv, envp);.br.B char *name, *argv[ ], *envp[ ];.PP.B extern char **environ;.SH DESCRIPTION.I Execin all its formsoverlays the calling process with the named file, thentransfers to theentry point of the core image of the file.There can be no return from a successful exec; the callingcore image is lost..PPFiles remain open across.I execunless explicit arrangement has been made;see.IR ioctl (2).Ignored signals remain ignored acrossthese calls, butsignals that are caught (see.IR signal (2))are resetto their default values..PPEach user has a.I realuser ID and group ID and an.I effectiveuser ID and group ID.TherealIDidentifies the person using the system;theeffectiveIDdetermines his access privileges..I Execchanges the effective user and group ID tothe owner of the executed file if the file has the `set-user-ID'or `set-group-ID'modes.Therealuser ID is not affected..PPThe.I nameargumentis a pointer to the name of the fileto be executed.The pointers.IR arg [ 0 ],.IR arg [ 1 "] ..."address null-terminated strings.Conventionally.IR arg [ 0 ]is the name of thefile..PPFrom C, two interfaces are available..I Execlis useful when a known file with known arguments isbeing called;the arguments to.I execlare the character stringsconstituting the file and the arguments;the first argument is conventionallythe same as the file name (or its last component).A 0 argument must end the argument list..PPThe.I execvversion is useful when the number of arguments is unknownin advance;the arguments to.I execvare the name of the file to beexecuted and a vector of strings containingthe arguments.The last argument string must be followedby a 0 pointer..PPWhen a C program is executed,it is called as follows:.PP main(argc, argv, envp).br int argc;.br char **argv, **envp;.PPwhere.IR argc ""is the argument countand.IR argv ""is an array of character pointersto the arguments themselves.As indicated,.IR argc ""is conventionally at least oneand the first member of the array points to astring containing the name of the file..PP.I Argvis directly usable in another.I execvbecause.IR argv [ argc ]is 0..PP.I Envpis a pointer to an array of strings that constitutethe.I environmentof the process.Each string consists of a name, an ``='', and a null-terminated value.The array of pointers is terminated by a null pointer.The shell.IR sh (1)passes an environment entry for each global shell variabledefined when the program is called.See.IR environ (5)for some conventionallyused names.The C run-time start-off routine places a copy of.I envpin the global cell.I environ,which is usedby.IR execv \ and \ execlto pass the environment to any subprograms executed by thecurrent program.The.I execroutines use lower-level routines as followsto pass an environment explicitly:.RS.nfexecle(file, arg0, arg1, . . . , argn, 0, environ);execve(file, argv, environ);.fi.RE.PP.I Execlpand.I execvpare called with the same arguments as.I execland.I execv,but duplicate the shell's actions in searching for an executablefile in a list of directories.The directory list is obtained from the environment..SH FILES.ta \w'/bin/sh 'u/bin/sh shell, invoked if command file foundby.I execlpor.I execvp.SH "SEE ALSO"fork(2), environ(5).SH DIAGNOSTICSIf the file cannot be found,if it is not executable,if it does not start with a valid magic number (see.IR a.out (5)),if maximum memory is exceeded,or if the arguments require too much space,a returnconstitutes the diagnostic;the return value is \-1.Even for the super-user,at least one of the execute-permission bits must be set fora file to be executed..SH BUGSIf.I execvpis called to execute a file that turns out to be a shellcommand file,and if it is impossible to execute the shell,the values of.I argv[0]and.I argv[\-1]will be modified before return..SH ASSEMBLER.DT(exec = 11.).br.B sys exec; name; argv.PP(exece = 59.).br.B sys exece; name; argv; envp.PPPlain.I execis obsoleted by.I exece,but remains for historical reasons..PPWhen the called file starts execution on the PDP11,the stack pointer points to a word containing the number of arguments.Just abovethis number is a list of pointers to the argument strings,followed by a null pointer, followed by the pointers tothe environment strings and then another null pointer.The strings themselves follow;a 0 word is left at the very top of memory..PP sp\(-> nargs.br arg0.br ....br argn.br 0.br env0.br ....br envm.br 0.PP arg0: <arg0\e0>.br ....br env0: <env0\e0>.br 0.PPOn the Interdata 8/32,the stack begins at a conventional place(currently 0xD0000)and grows upwards.After.I exec,the layout of data on the stack is as follows..PP.nf int 0 arg0: byte ... ...argp0: int arg0 ... int 0envp0: int env0 ... int 0 %2\(-> space 40 int nargs int argp0 int envp0 %3\(->.fi.PPThis arrangement happens to conform well to C calling conventions.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -