📄 execve.2
字号:
.\" Copyright (c) 1980, 1991, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)execve.2 8.3 (Berkeley) 1/24/94.\".Dd January 24, 1994.Dt EXECVE 2.Os BSD 4.Sh NAME.Nm execve.Nd execute a file.Sh SYNOPSIS.Fd #include <unistd.h>.Ft int.Fn execve "const char *path" "char *const argv[]" "char *const envp[]".Sh DESCRIPTION.Fn Execvetransforms the calling process into a new process.The new process is constructed from an ordinary file,whose name is pointed to by.Fa path ,called the.Em new process file .This file is either an executable object file,or a file of data for an interpreter.An executable object file consists of an identifying header,followed by pages of data representing the initial program (text)and initialized data pages. Additional pages may be specifiedby the header to be initialized with zero data; see.Xr a.out 5 ..PpAn interpreter file begins with a line of the form:.Pp.Bd -filled -offset indent -compact.Sy \&#!.Em interpreter.Bq Em arg.Ed.PpWhen an interpreter file is.Fn execve Ap d ,the system.Fn execve Ap sruns the specified.Em interpreter .If the optional.Em argis specified, it becomes the first argument to the.Em interpreter ,and the name of the originally.Fn execve Ap dfile becomes the second argument;otherwise, the name of the originally.Fn execve Ap dfile becomes the first argument. The original arguments are shifted over tobecome the subsequent arguments. The zeroth argument, normally the name of the.Fn execve Ap dfile, is left unchanged..PpThe argument.Fa argvis a pointer to a null-terminated array ofcharacter pointers to null-terminated character strings.These strings construct the argument list to be made available to the newprocess. At least one argument must be present inthe array; by custom, the first element should bethe name of the executed program (for example, the last component of.Fa path ) ..PpThe argument.Fa envpis also a pointer to a null-terminated array ofcharacter pointers to null-terminated strings.A pointer to this array is normally stored in the global variable.Va environ.These strings pass information to thenew process that is not directly an argument to the command (see.Xr environ 7 ) ..PpFile descriptors open in the calling process image remain open inthe new process image, except for those for which the close-on-execflag is set (see.Xr close 2and.Xr fcntl 2 ) .Descriptors that remain open are unaffected by.Fn execve ..PpSignals set to be ignored in the calling process are set to be ignored inthenew process. Signals which are set to be caught in the calling process imageare set to default action in the new process image.Blocked signals remain blocked regardless of changes to the signal action.The signal stack is reset to be undefined (see.Xr sigaction 2for more information)..PpIf the set-user-ID mode bit of the new process image file is set(see.Xr chmod 2 ) ,the effective user ID of the new process image is set to the owner IDof the new process image file.If the set-group-ID mode bit of the new process image file is set,the effective group ID of the new process image is set to the group IDof the new process image file.(The effective group ID is the first element of the group list.)The real user ID, real group ID andother group IDs of the new process image remain the same as the callingprocess image.After any set-user-ID and set-group-ID processing,the effective user ID is recorded as the saved set-user-ID,and the effective group ID is recorded as the saved set-group-ID.These values may be used in changing the effective IDs later (see.Xr setuid 2 ) ..PpThe new process also inherits the following attributes fromthe calling process:.Pp.Bl -column parent_process_ID -offset indent -compact.It process ID Ta see Xr getpid 2.It parent process ID Ta see Xr getppid 2.It process group ID Ta see Xr getpgrp 2.It access groups Ta see Xr getgroups 2.It working directory Ta see Xr chdir 2.It root directory Ta see Xr chroot 2.It control terminal Ta see Xr termios 4.It resource usages Ta see Xr getrusage 2.It interval timers Ta see Xr getitimer 2.It resource limits Ta see Xr getrlimit 2.It file mode mask Ta see Xr umask 2.It signal mask Ta see Xr sigvec 2 ,.Xr sigsetmask 2.El.PpWhen a program is executed as a result of an.Fn execvecall, it is entered as follows:.Bd -literal -offset indentmain(argc, argv, envp)int argc;char **argv, **envp;.Ed.Ppwhere.Fa argcis the number of elements in.Fa argv(the ``arg count'')and.Fa argvpoints to the array of character pointersto the arguments themselves..Sh RETURN VALUESAs the.Fn execvefunction overlays the current process image with a new process image the successful callhas no process to return to.If.Fn execvedoes return to the calling process an error has occurred; thereturn value will be -1 and the global variable.Va errnois set to indicate the error..Sh ERRORS.Fn Execvewill fail and return to the calling process if:.Bl -tag -width [ENAMETOOLONG].It Bq Er ENOTDIRA component of the path prefix is not a directory..It Bq Er EINVALThe pathname contains a character with the high-order bit set..It Bq Er ENAMETOOLONGA component of a pathname exceeded 255 characters,or an entire path name exceeded 1023 characters..It Bq Er ENOENTThe new process file does not exist..It Bq Er ELOOPToo many symbolic links were encountered in translating the pathname..It Bq Er EACCESSearch permission is denied for a component of the path prefix..It Bq Er EACCESThe new process file is not an ordinary file..It Bq Er EACCESThe new process file mode denies execute permission..It Bq Er ENOEXECThe new process file has the appropriate accesspermission, but has an invalid magic number in its header..It Bq Er ETXTBSYThe new process file is a pure procedure (shared text)file that is currently open for writing or reading by some process..It Bq Er ENOMEMThe new process requires more virtual memory thanis allowed by the imposed maximum.Pq Xr getrlimit 2 ..It Bq Er E2BIGThe number of bytes in the new process's argument listis larger than the system-imposed limit.The limit in the system as released is 20480 bytes.Pf ( Dv NCARGSin.Ao Pa sys/param.h Ac ..It Bq Er EFAULTThe new process file is not as long as indicated bythe size values in its header..It Bq Er EFAULT.Fa Path ,.Fa argv ,or.Fa envppointto an illegal address..It Bq Er EIOAn I/O error occurred while reading from the file system..El.Sh CAVEATIf a program is.Em setuidto a non-super-user, but is executed whenthe real.Em uidis ``root'', then the program has some of the powersof a super-user as well..Sh SEE ALSO.Xr exit 2 ,.Xr fork 2 ,.Xr execl 3 ,.Xr environ 7.Sh HISTORYThe.Nmfunction call appeared in.Bx 4.2 .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -