execve.2
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 261 行
2
261 行
.\" SCCSID: @(#)execve.2 6.6 3/15/90.TH execve 2.SH Nameexecve \- execute a file.SH Syntax.ft Bexecve(name, argv, envp).brchar *name, *argv[], *envp[];.fi.SH Description.NXR "execve system call".NXA "execve system call" "environ global variable".NXR "file" "executing"The.PN execvesystem call transforms the calling process into a new process.The new process is constructed from an ordinary filecalled the \fInew process file\fP..NXR "new process file" "defined"This file is either an executable object file,.NXR "executable object file" "defined"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 can be specifiedby the header to be initialized with zero data.For further information, see .MS a.out 5 ..PPAn interpreter file begins with a line of the form ``#! \fIinterpreter\fP''..NXR "interpreter file" "defined"When an interpreter file is executedthe system executes the specified interpreter, givingit the name of the originally executed file as an argument,shifting over the rest of the original arguments..PPThere can be no return froma successful .PN execvebecause the callingcore image is lost.This is the mechanism whereby different process images become active..PPThe argument \fIargv\fP is an array of character pointersto null-terminated character strings. These strings constitutethe argument list to be made available to the newprocess. By convention, at least one argument must be present inthis array, and the first element of this array should bethe name of the executed program, the last component of \fIname\fP..PPThe argument \fIenvp\fP is also an array of character pointersto null-terminated strings. These strings pass information to thenew process, but they are not directly arguments to the command.For further information, see .MS environ 7 ..PPDescriptors open in the calling process remain open inthe new process, except for those for which the .I close-on-execflag is set. For further information, see .MS close 2 .Descriptors which remain open are unaffected by.PN execve ..PPIgnored signals remain ignored across an.PN execve ,but signals that are caught are reset to their default values.The signal stack is reset to be undefined. For further information,see .MS sigvec 2 ..PPEach process has.I realuser and group IDs and.I effectiveuser and group IDs. The.I realID identifies the person using the system; the.I effectiveID determines his access privileges.The.PN execvesystem callchanges the effective user and group ID tothe owner of the executed file if the file has the set-user-IDor set-group-ID modes. The.I realuser ID is not affected..PPThe new process also inherits the following attributes fromthe calling process:.PP.in +5n.nf.ta +2iProcess ID See getpid(2)Parent process ID See getpid(2)Process group ID See getpgrp(2)Access groups See getgroups(2)Working directory See chdir(2)root directory See chroot(2)Control terminal See tty(4)Resource usages See getrusage(2)Interval timers See getitimer(2)Resource limits See getrlimit(2)File mode mask See umask(2)Signal mask See sigvec(2).in \-5n.fi.PPWhen the executed program begins, it is called as follows:.PP.DT.nf main(argc, argv, envp) int argc; char **argv, **envp;.fi.PPThe.I argcargument is the number of elements in \fIargv\fP(the ``arg count'')and.I argvis the array of character pointersto the arguments themselves..PPThe.I envpargument is a pointer to an array of strings that constitutethe.I environmentof the process.A pointer to this array is also storedin the global environ variable.Each string consists of a name,an equal sign ( = ), and a null-terminated value.The array of pointers is terminated by a null pointer.The shell .MS sh 1passes an environment entry for each global shell variabledefined when the program is called.See .MS environ 7for some conventionally used names..PPIf.PN execvereturns to the calling process, an error has occurred; thereturn value is \-1 and the global variableerrnocontains an error code..SH Environment.SS POSIX, System Five When your program is compiled using the POSIX or System V environment,theeffective user ID and effective group ID of the new process imageare saved (as the saved-set-uid and saved-set-gid)for later use by the.PN setuid ,.PN setgid ,and.PN killfunctions..SH Restrictions.NXR "execve system call" "restricted"If a program's effective user ID is not the superuser,but it is executed whenthe real user ID is root, then the program has the powersof the superuser. .SH Diagnostics.NXR "execve system call" "diagnostics"The.PN execvesystem call fails and returns to the calling process under the followingconditions:.TP 15[ENOENT]The new process file does not exist..TP 15[ENOTDIR]A component of the path prefix is not a directory..TP 15[EACCES]Search permission is denied for a component of the path prefix..TP 15[EACCES]The new process file is not an ordinary file..TP 15[EACCES]The new process file mode denies execute permission..TP 15[ENOEXEC]The new process file has the appropriate accesspermission, but it has an invalid magic number in its header..TP 15[ETXTBSY]The new process file is a pure procedure (shared text)file that is currently open for writing or reading by some process..TP 15[ENOMEM]The new process requires more virtual memory thanis allowed by the imposed maximum. For further information,see .MS getrlimit 2 ..TP 15[E2BIG]The number of bytes in the new process's argument listis larger than the system-imposed limit of {ARG_MAX} bytes..TP 15[EFAULT]The new process file is not as long as indicated bythe size values in its header..TP 15[EFAULT]The\fIpath\fP\|, \fIargv\fP\|, or \fIenvp\fP pointsto an illegal address..TP 15[EIO]An I/O error occurred while reading from the file system..TP 15[ENAMETOOLONG]A component of a pathname exceeded 255 characters, or anentire path name exceeded 1023 characters..TP 15[ELOOP]Too many symbolic links were encountered in translating thepathname..TP 15[EROFS]If binaries cannot be executed from the file system..TP 15[EROFS]If.PN setuidand.PN setgidprograms cannot be executed from the file system..TP 15[ESTALE]The file handle given in the argument is invalid. The filereferred to by that file handle no longer exists or has been revoked..TP[ETIMEDOUT]A connect request or remote file operation failedbecause the connected partydid not properly respond after a periodof time that is dependent on the communications protocol..SH See Alsoexit(2), fork(2), execl(3), environ(7)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?