Annotation of researchv10dc/man/man2/exec.2, revision 1.1.1.1

1.1       root        1: .TH EXEC 2
                      2: .CT 2 proc_man
                      3: .SH NAME
                      4: execl, execv, execle, execve, execlp, execvp, exect \(mi execute a file
                      5: .SH SYNOPSIS
                      6: .nf
                      7: .B int "execl(name, arg0, arg1, ..., argn, (char *)0)"
                      8: .B char *name, *arg0, *arg1, ..., *argn;
                      9: .PP
                     10: .B int execv(name, argv)
                     11: .B char *name, *argv[];
                     12: .PP
                     13: .B "int execle(name, arg0, arg1, ..., argn, (char *)0, envp)"
                     14: .B "char *name, *arg0, *arg1, ..., *argn, *envp[];"
                     15: .PP
                     16: .B int execve(name, argv, envp)
                     17: .B char *name, *argv[], *envp[];
                     18: .PP
                     19: .B int "execlp(name, arg0, arg1, ..., argn, (char *)0)"
                     20: .B char *name, *arg0, *arg1, ..., *argn;
                     21: .PP
                     22: .B int execvp(name, argv)
                     23: .B char *name, *argv[];
                     24: .PP
                     25: .B int exect(name, argv, envp)
                     26: .B char *name, *argv[], *envp[];
                     27: .fi
                     28: .SH DESCRIPTION
                     29: .I Exec
                     30: in all its forms
                     31: overlays the calling process with the named file, then
                     32: transfers to the
                     33: entry point of the image of the file.
                     34: There can be no return from a successful
                     35: .IR exec ;
                     36: the calling image is lost.
                     37: .PP
                     38: Files remain open across
                     39: .I exec
                     40: unless explicit arrangement has been made;
                     41: see
                     42: .IR ioctl (2).
                     43: Signals that are caught (see
                     44: .IR signal (2))
                     45: are reset
                     46: to their default values.
                     47: Other signal settings
                     48: are unchanged.
                     49: .PP
                     50: Each user has a
                     51: .I real
                     52: userid and groupid and an
                     53: .I effective
                     54: userid and groupid.
                     55: The real userid (groupid)
                     56: identifies the person using the system;
                     57: the effective userid (groupid)
                     58: determines access privileges.
                     59: .I Exec
                     60: changes the effective userid and groupid to
                     61: the owner of the executed file if the file has the set-userid
                     62: or set-groupid modes.
                     63: The real userid is not affected.
                     64: .PP
                     65: .I Name
                     66: points to the name of the file
                     67: to be executed.
                     68: It must be a regular file
                     69: (type
                     70: .BR S_IFREG ,
                     71: see
                     72: .IR stat (2))
                     73: and its permissions must allow execution.
                     74: .I Arg0, arg1, ...
                     75: or the pointers in
                     76: .I argv
                     77: address null-terminated argument strings
                     78: to be made available when the new image starts.
                     79: .I Argv
                     80: must end with a 0 pointer.
                     81: Conventionally argument 0
                     82: is the name of the program.
                     83: .PP
                     84: In
                     85: .IR execle ,
                     86: .IR execve ,
                     87: and
                     88: .IR exect ,
                     89: the
                     90: .I envp
                     91: array contains pointers to
                     92: a set of null-terminated strings
                     93: composing the environment of the process.
                     94: .I Envp
                     95: must end with a 0 pointer.
                     96: The other calls
                     97: copy the present environment
                     98: from the global cell
                     99: .IR environ ;
                    100: see
                    101: .IR environ (5).
                    102: .PP
                    103: The
                    104: .I execl
                    105: and
                    106: .I execv
                    107: forms
                    108: differ only in argument syntax;
                    109: one is more convenient when the number of arguments is known in advance,
                    110: the other when arguments are assembled on the fly.
                    111: .PP
                    112: If the first two bytes of the file
                    113: are the characters
                    114: .LR #! ,
                    115: subsequent text up to a newline is examined.
                    116: The first word,
                    117: up to a blank or tab,
                    118: names an interpreter program;
                    119: anything left over is a single supplemental argument.
                    120: The original
                    121: .IR name ,
                    122: preceded by the supplemental argument if any,
                    123: is inserted in the argument list
                    124: between
                    125: .I arg0
                    126: and
                    127: .I arg1
                    128: (or between the first pair of
                    129: .I argv
                    130: pointers).
                    131: The interpreter is executed with the modified argument list.
                    132: .PP
                    133: If the file doesn't start with
                    134: .LR #! ,
                    135: a standard header for
                    136: a binary image
                    137: is expected;
                    138: see
                    139: .IR a.out (5).
                    140: If the file doesn't begin with a valid header either,
                    141: .B ENOEXEC
                    142: is returned.
                    143: The shell
                    144: .IR sh (1)
                    145: takes this to mean that the file
                    146: contains shell commands.
                    147: .PP
                    148: When a C program is executed,
                    149: it is called as follows:
                    150: .IP
                    151: .EX
                    152: main(argc, argv, envp)
                    153: int argc;
                    154: char **argv, **envp;
                    155: .EE
                    156: .PP
                    157: .I Argv
                    158: is the array of argument pointers passed to
                    159: .IR exec ;
                    160: .I argc
                    161: is the number of arguments.
                    162: .I Argv
                    163: is directly usable in a subsequent
                    164: .I execv
                    165: because
                    166: .BR argv[argc]==0 .
                    167: .I Envp
                    168: is the environment array;
                    169: the same value has already been stored in
                    170: .IR environ .
                    171: .PP
                    172: .I Execlp
                    173: and
                    174: .I execvp
                    175: take the same arguments as
                    176: .I execl
                    177: and
                    178: .IR execv ,
                    179: but search the directories listed in the
                    180: .B PATH
                    181: environment variable
                    182: for an executable file called
                    183: .IR name ,
                    184: mimicking the shell's path search.
                    185: .PP
                    186: .I Exect
                    187: is the same as
                    188: .IR execve ,
                    189: except that it arranges for the process to stop
                    190: just before the first instruction of the new image;
                    191: see
                    192: .IR proc (4).
                    193: .SH FILES
                    194: .TF /bin/sh
                    195: .TP
                    196: .F /bin/sh
                    197: shell, invoked if command file found
                    198: by
                    199: .I execlp
                    200: or
                    201: .I execvp
                    202: .SH EXAMPLES
                    203: This file,
                    204: if created with execute permissions
                    205: and run by
                    206: .IR exec ,
                    207: calls
                    208: .IR awk (1)
                    209: to count the lines in all the files named in its arguments:
                    210: .EX
                    211: #!/usr/bin/awk -f
                    212: END    { print NR }
                    213: .EE
                    214: .SH "SEE ALSO"
                    215: .IR sh (1),
                    216: .IR fork (2), 
                    217: .IR ioctl (2),
                    218: .IR signal (2),
                    219: .IR proc (4),
                    220: .IR environ (5)
                    221: .SH DIAGNOSTICS
                    222: .BR E2BIG ,
                    223: .BR EACCES ,
                    224: .BR EFAULT ,
                    225: .BR EIO ,
                    226: .BR ELOOP ,
                    227: .BR ENOENT ,
                    228: .BR ENOEXEC ,
                    229: .BR ENOMEM ,
                    230: .BR ENOTDIR ,
                    231: .BR ENXIO ,
                    232: .BR ETXTBSY
                    233: .SH BUGS
                    234: If
                    235: .I execvp
                    236: is called to execute a file that turns out to be a shell
                    237: command file,
                    238: and the shell cannot be executed,
                    239: some of the values in
                    240: .I argv
                    241: may be modified before return.
                    242: .br
                    243: Neither the shell's path search
                    244: nor that of
                    245: .I execlp
                    246: and
                    247: .I execvp
                    248: extends to the interpreter named after
                    249: .LR #! .
                    250: The interpreter file
                    251: may not itself begin with
                    252: .LR #! .
                    253: The text after
                    254: .LR #!
                    255: may be no more than 30 characters long,
                    256: including the newline.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.