nightly: remove unused BINARCHIVE
[unleashed.git] / share / man / man2 / exec.2
blobbfc5383dfc7be92210b270b505f07d81fb76aad8
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T.
44 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
45 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
46 .\" Copyright 2015, Joyent, Inc.
47 .\"
48 .TH EXEC 2 "Oct 27, 2015"
49 .SH NAME
50 exec, execl, execle, execlp, execv, execve, execvp \- execute a file
51 .SH SYNOPSIS
52 .LP
53 .nf
54 #include <unistd.h>
56 \fBint\fR \fBexecl\fR(\fBconst char *\fR\fIpath\fR, \fBconst char *\fR\fIarg0\fR, \fB\&...
57      /* const char *\fR\fIargn\fR, \fB(char *)0 */);\fR
58 .fi
60 .LP
61 .nf
62 \fBint\fR \fBexecv\fR(\fBconst char *\fR\fIpath\fR, \fBchar *const\fR \fIargv[]\fR);
63 .fi
65 .LP
66 .nf
67 \fBint\fR \fBexecle\fR(\fBconst char *\fR\fIpath\fR, \fBconst char *\fR\fIarg0\fR, \fB\&...
68      /* const char *\fR\fIargn\fR, \fB(char *)0\fR,\fBchar *const\fR \fIenvp\fR[]*/);
69 .fi
71 .LP
72 .nf
73 \fBint\fR \fBexecve\fR(\fBconst char *\fR\fIpath\fR, \fBchar *const\fR \fIargv[]\fR,
74      \fBchar *const\fR \fIenvp[]\fR);
75 .fi
77 .LP
78 .nf
79 \fBint\fR \fBexeclp\fR(\fBconst char *\fR\fIfile\fR, \fBconst char *\fR\fIarg0\fR, \fB\&...
80      /* const char *\fR\fIargn\fR, \fB(char *)0 */);\fR
81 .fi
83 .LP
84 .nf
85 \fBint\fR \fBexecvp\fR(\fBconst char *\fR\fIfile\fR, \fBchar *const\fR \fIargv[]\fR);
86 .fi
88 .SH DESCRIPTION
89 .LP
90 Each of the functions in the \fBexec\fR family replaces the current process
91 image with a new process image. The new image is constructed from a regular,
92 executable file called the \fBnew process image file\fR. This file is either an
93 executable object file or a file of data for an interpreter. There is no return
94 from a successful call to one of these functions because the calling process
95 image is overlaid by the new process image.
96 .sp
97 .LP
98 An interpreter file begins with a line of the form
99 .sp
100 .in +2
102 #! pathname [\fIarg\fR]
104 .in -2
108 where \fIpathname\fR is the path of the interpreter, and \fIarg\fR is an
109 optional argument. When an interpreter file is executed, the system invokes the
110 specified interpreter. The pathname specified in the interpreter file is passed
111 as \fIarg0\fR to the interpreter. If \fIarg\fR was specified in the interpreter
112 file, it is passed as \fIarg1\fR to the interpreter. The remaining arguments to
113 the interpreter are \fIarg0\fR through \fIargn\fR of the originally exec'd
114 file. The interpreter named by \fIpathname\fR may also be an interpreter file.
115 There can be up to four nested interpreter files before the final interpreter.
116 The setid bits on nested interpreters are silently ignored.
119 When a C-language program is executed as a result of this call, it is entered
120 as a C-language function call as follows:
122 .in +2
124 int main (int argc, char *argv[]);
126 .in -2
130 where \fIargc\fR is the argument count and \fIargv\fR is an array of character
131 pointers to the arguments themselves. In addition, the following variable:
133 .in +2
135 extern char **environ;
137 .in -2
141 is initialized as a pointer to an array of character pointers to the
142 environment strings. The \fIargv\fR and \fIenviron\fR arrays are each
143 terminated by a null pointer. The null pointer terminating the \fIargv\fR array
144 is not counted in \fIargc\fR.
147 The value of \fIargc\fR is non-negative, and if greater than 0, \fIargv\fR[0]
148 points to a string containing the name of the file. If \fIargc\fR is 0,
149 \fIargv\fR[0] is a null pointer, in which case there are no arguments.
150 Applications should verify that \fIargc\fR is greater than 0 or that
151 \fIargv\fR[0] is not a null pointer before dereferencing \fIargv\fR[0].
154 The arguments specified by a program with one of the \fBexec\fR functions are
155 passed on to the new process image in the \fBmain()\fR arguments.
158 The \fIpath\fR argument points to a path name that identifies the new process
159 image file.
162 The \fIfile\fR argument is used to construct a pathname that identifies the new
163 process image file. If the \fIfile\fR argument contains a slash character, it
164 is used as the pathname for this file. Otherwise, the path prefix for this file
165 is obtained by a search of the directories passed in the \fBPATH\fR environment
166 variable (see \fBenviron\fR(5)). The environment is supplied typically by the
167 shell. If the process image file is not a valid executable object file,
168 \fBexeclp()\fR and \fBexecvp()\fR use the contents of that file as standard
169 input to the shell. In this case, the shell becomes the new process image. The
170 standard to which the caller conforms determines which shell is used. See
171 \fBstandards\fR(5).
174 The arguments represented by \fIarg0\fR\&.\|.\|. are pointers to
175 null-terminated character strings. These strings constitute the argument list
176 available to the new process image. The list is terminated by a null pointer.
177 The \fIarg0\fR argument should point to a filename that is associated with the
178 process being started by one of the \fBexec\fR functions.
181 The \fIargv\fR argument is an array of character pointers to null-terminated
182 strings. The last member of this array must be a null pointer. These strings
183 constitute the argument list available to the new process image. The value in
184 \fIargv\fR[0] should point to a filename that is associated with the process
185 being started by one of the \fBexec\fR functions.
188 The \fIenvp\fR argument is an array of character pointers to null-terminated
189 strings. These strings constitute the environment for the new process image.
190 The \fIenvp\fR array is terminated by a null pointer. For \fBexecl()\fR,
191 \fBexecv()\fR, \fBexecvp()\fR, and \fBexeclp()\fR, the C-language run-time
192 start-off routine places a pointer to the environment of the calling process in
193 the global object \fBextern char **environ\fR, and it is used to pass the
194 environment of the calling process to the new process image.
197 The number of bytes available for the new process's combined argument and
198 environment lists is \fBARG_MAX\fR. It is implementation-dependent whether null
199 terminators, pointers, and/or any alignment bytes are included in this total.
202 File descriptors open in the calling process image remain open in the new
203 process image, except for those whose close-on-exec flag \fBFD_CLOEXEC\fR is
204 set; see \fBfcntl\fR(2). For those file descriptors that remain open, all
205 attributes of the open file description, including file locks, remain
206 unchanged.
209 The preferred hardware address translation size (see \fBmemcntl\fR(2)) for the
210 stack and heap of the new process image are set to the default system page
211 size.
214 Directory streams open in the calling process image are closed in the new
215 process image.
218 The state of conversion descriptors and message catalogue descriptors in the
219 new process image is undefined. For the new process, the equivalent of:
221 .in +2
223 setlocale(LC_ALL, "C")
225 .in -2
229 is executed at startup.
232 Signals set to the default action (\fBSIG_DFL\fR) in the calling process image
233 are set to the default action in the new process image (see \fBsignal\fR(3C)).
234 Signals set to be ignored (\fBSIG_IGN\fR) by the calling process image are set
235 to be ignored by the new process image. Signals set to be caught by the calling
236 process image are set to the default action in the new process image (see
237 \fBsignal.h\fR(3HEAD)). After a successful call to any of the \fBexec\fR
238 functions, alternate signal stacks are not preserved and the \fBSA_ONSTACK\fR
239 flag is cleared for all signals.
242 After a successful call to any of the \fBexec\fR functions, any functions
243 previously registered by \fBatexit\fR(3C) are no longer registered.
246 The saved resource limits in the new process image are set to be a copy of the
247 process's corresponding hard and soft resource limits.
250 If the \fBST_NOSUID\fR bit is set for the file system containing the new
251 process image file, then the effective user \fBID\fR and effective group
252 \fBID\fR are unchanged in the new process image. If the set-user-\fBID\fR mode
253 bit of the new process image file is set (see \fBchmod\fR(2)), the effective
254 user \fBID\fR of the new process image is set to the owner \fBID\fR of the new
255 process image file. Similarly, if the set-group-\fBID\fR mode bit of the new
256 process image file is set, the effective group \fBID\fR of the new process
257 image is set to the group \fBID\fR of the new process image file. The real user
258 \fBID\fR and real group \fBID\fR of the new process image remain the same as
259 those of the calling process image. The effective user ID and effective group
260 ID of the new process image are saved (as the saved set-user-ID and the saved
261 set-group-ID for use by \fBsetuid\fR(2).
264 The privilege sets are changed according to the following rules:
265 .RS +4
268 The inheritable set, I, is intersected with the limit set, L.  This
269 mechanism enforces the limit set for processes.
271 .RS +4
274 The effective set, E, and the permitted set, P, are made equal to the new
275 inheritable set.
279 The system attempts to set the privilege-aware state to non-PA both before
280 performing any modifications to the process IDs and privilege sets as well as
281 after completing the transition to new UIDs and privilege sets, following the
282 rules outlined in \fBprivileges\fR(5).
285 If the {\fBPRIV_PROC_OWNER\fR} privilege is asserted in the effective set, the
286 set-user-ID and set-group-ID bits will be honored when the process is being
287 controlled by \fBptrace\fR(3C). Additional restriction can apply when the
288 traced process has an effective UID of 0. See \fBprivileges\fR(5).
291 Any shared memory segments attached to the calling process image will not be
292 attached to the new process image (see \fBshmop\fR(2)). Any mappings
293 established through \fBmmap()\fR are not preserved across an \fBexec\fR. Memory
294 mappings created in the process are unmapped before the address space is
295 rebuilt for the new process image. See \fBmmap\fR(2).
298 Memory locks established by the calling process via calls to \fBmlockall\fR(3C)
299 or \fBmlock\fR(3C) are removed. If locked pages in the address space of the
300 calling process are also mapped into the address spaces the locks established
301 by the other processes will be unaffected by the call by this process to the
302 \fBexec\fR function. If the \fBexec\fR function fails, the effect on memory
303 locks is unspecified.
306 If \fB_XOPEN_REALTIME\fR is defined and has a value other than \(mi1, any named
307 semaphores open in the calling process are closed as if by appropriate calls to
308 \fBsem_close\fR(3C)
311 Profiling is disabled for the new process; see \fBprofil\fR(2).
314 Timers created by the calling process with \fBtimer_create\fR(3C) are deleted
315 before replacing the current process image with the new process image.
318 For the \fBSCHED_FIFO\fR and \fBSCHED_RR\fR scheduling policies, the policy and
319 priority settings are not changed by a call to an \fBexec\fR function.
322 All open message queue descriptors in the calling process are closed, as
323 described in \fBmq_close\fR(3C).
326 Any outstanding asynchronous I/O operations may be cancelled. Those
327 asynchronous I/O operations that are not canceled will complete as if the
328 \fBexec\fR function had not yet occurred, but any associated signal
329 notifications are suppressed. It is unspecified whether the \fBexec\fR function
330 itself blocks awaiting such I/O completion. In no event, however, will the new
331 process image created by the \fBexec\fR function be affected by the presence of
332 outstanding asynchronous I/O operations at the time the \fBexec\fR function is
333 called.
336 All active contract templates are cleared (see \fBcontract\fR(4)).
339 The new process also inherits the following attributes from the calling
340 process:
341 .RS +4
343 .ie t \(bu
344 .el o
345 controlling terminal
347 .RS +4
349 .ie t \(bu
350 .el o
351 current working directory
353 .RS +4
355 .ie t \(bu
356 .el o
357 file-locks (see \fBfcntl\fR(2) and \fBlockf\fR(3C))
359 .RS +4
361 .ie t \(bu
362 .el o
363 file mode creation mask (see \fBumask\fR(2))
365 .RS +4
367 .ie t \(bu
368 .el o
369 file size limit (see \fBulimit\fR(2))
371 .RS +4
373 .ie t \(bu
374 .el o
375 limit privilege set
377 .RS +4
379 .ie t \(bu
380 .el o
381 nice value (see \fBnice\fR(2))
383 .RS +4
385 .ie t \(bu
386 .el o
387 parent process \fBID\fR
389 .RS +4
391 .ie t \(bu
392 .el o
393 pending signals (see \fBsigpending\fR(2))
395 .RS +4
397 .ie t \(bu
398 .el o
399 privilege debugging flag (see \fBprivileges\fR(5) and \fBgetpflags\fR(2))
401 .RS +4
403 .ie t \(bu
404 .el o
405 process \fBID\fR
407 .RS +4
409 .ie t \(bu
410 .el o
411 process contract (see \fBcontract\fR(4) and \fBprocess\fR(4))
413 .RS +4
415 .ie t \(bu
416 .el o
417 process group \fBID\fR
419 .RS +4
421 .ie t \(bu
422 .el o
423 process signal mask (see \fBsigprocmask\fR(2))
425 .RS +4
427 .ie t \(bu
428 .el o
429 processor bindings (see \fBprocessor_bind\fR(2))
431 .RS +4
433 .ie t \(bu
434 .el o
435 processor set bindings (see \fBpset_bind\fR(2))
437 .RS +4
439 .ie t \(bu
440 .el o
441 project \fBID\fR
443 .RS +4
445 .ie t \(bu
446 .el o
447 real group \fBID\fR
449 .RS +4
451 .ie t \(bu
452 .el o
453 real user \fBID\fR
455 .RS +4
457 .ie t \(bu
458 .el o
459 resource limits (see \fBgetrlimit\fR(2))
461 .RS +4
463 .ie t \(bu
464 .el o
465 root directory
467 .RS +4
469 .ie t \(bu
470 .el o
471 scheduler class and priority (see \fBpriocntl\fR(2))
473 .RS +4
475 .ie t \(bu
476 .el o
477 \fBsemadj\fR values (see \fBsemop\fR(2))
479 .RS +4
481 .ie t \(bu
482 .el o
483 session membership (see \fBexit\fR(2) and \fBsignal\fR(3C))
485 .RS +4
487 .ie t \(bu
488 .el o
489 supplementary group \fBIDs\fR
491 .RS +4
493 .ie t \(bu
494 .el o
495 task \fBID\fR
497 .RS +4
499 .ie t \(bu
500 .el o
501 time left until an alarm clock signal (see \fBalarm\fR(2))
503 .RS +4
505 .ie t \(bu
506 .el o
507 \fBtms_utime\fR, \fBtms_stime\fR, \fBtms_cutime\fR, and \fBtms_cstime\fR (see
508 \fBtimes\fR(2))
510 .RS +4
512 .ie t \(bu
513 .el o
514 trace flag (see \fBptrace\fR(3C) request 0)
518 A call to any \fBexec\fR function from a process with more than one thread
519 results in all threads being terminated and the new executable image being
520 loaded and executed. No destructor functions will be called.
523 Upon successful completion, each of the functions in the \fBexec\fR family
524 marks for update the \fBst_atime\fR field of the file.  If an \fBexec\fR
525 function failed but was able to locate the \fBprocess image file\fR, whether
526 the \fBst_atime\fR field is marked for update is unspecified. Should the
527 function succeed, the process image file is considered to have been opened with
528 \fBopen\fR(2). The corresponding \fBclose\fR(2) is considered to occur at a
529 time after this open, but before process termination or successful completion
530 of a subsequent call to one of the \fBexec\fR functions. The \fIargv\fR[\|] and
531 \fIenvp\fR[\|] arrays of pointers and the strings to which those arrays point
532 will not be modified by a call to one of the \fBexec\fR functions, except as a
533 consequence of replacing the process image.
536 The saved resource limits in the new process image are set to be a copy of the
537 process's corresponding hard and soft limits.
538 .SH RETURN VALUES
540 If a function in the \fBexec\fR family returns to the calling process image, an
541 error has occurred; the return value is \fB\(mi1\fR and \fBerrno\fR is set to
542 indicate the error.
543 .SH ERRORS
545 The \fBexec\fR functions will fail if:
547 .ne 2
549 \fB\fBE2BIG\fR\fR
551 .RS 16n
552 The number of bytes in the new process's argument list is greater than the
553 system-imposed limit of {\fBARG_MAX\fR} bytes. The argument list limit is sum
554 of the size of the argument list plus the size of the environment's exported
555 shell variables.
559 .ne 2
561 \fB\fBEACCES\fR\fR
563 .RS 16n
564 Search permission is denied for a directory listed in the new process file's
565 path prefix.
567 The new process file is not an ordinary file.
569 The new process file mode denies execute permission.
571 The {\fBFILE_DAC_SEARCH\fR} privilege overrides the restriction on directory
572 searches.
574 The {\fBFILE_DAC_EXECUTE\fR} privilege overrides the lack of execute
575 permission.
579 .ne 2
581 \fB\fBEAGAIN\fR\fR
583 .RS 16n
584 Total amount of system memory available when reading using raw I/O is
585 temporarily insufficient.
589 .ne 2
591 \fB\fBEFAULT\fR\fR
593 .RS 16n
594 An argument points to an illegal address.
598 .ne 2
600 \fB\fBEINVAL\fR\fR
602 .RS 16n
603 The new process image file has the appropriate permission and has a recognized
604 executable binary format, but the system does not support execution of a file
605 with this format.
609 .ne 2
611 \fB\fBEINTR\fR\fR
613 .RS 16n
614 A signal was caught during the execution of one of the functions in the
615 \fIexec\fR family.
619 .ne 2
621 \fB\fBELOOP\fR\fR
623 .RS 16n
624 Too many symbolic links were encountered in translating \fIpath\fR or
625 \fIfile\fR, or too many nested interpreter files.
629 .ne 2
631 \fB\fBENAMETOOLONG\fR\fR
633 .RS 16n
634 The length of the \fIfile\fR or \fIpath\fR argument exceeds {\fBPATH_MAX\fR},
635 or the length of a \fIfile\fR or \fIpath\fR component exceeds {\fBNAME_MAX\fR}
636 while {\fB_POSIX_NO_TRUNC\fR} is in effect.
640 .ne 2
642 \fB\fBENOENT\fR\fR
644 .RS 16n
645 One or more components of the new process path name of the file do not exist or
646 is a null pathname.
650 .ne 2
652 \fB\fBENOLINK\fR\fR
654 .RS 16n
655 The \fIpath\fR argument points to a remote machine and the link to that machine
656 is no longer active.
660 .ne 2
662 \fB\fBENOTDIR\fR\fR
664 .RS 16n
665 A component of the new process path of the file prefix is not a directory.
670 The \fBexec\fR functions, except for \fBexeclp()\fR and \fBexecvp()\fR, will
671 fail if:
673 .ne 2
675 \fB\fBENOEXEC\fR\fR
677 .RS 11n
678 The new process image file has the appropriate access permission but is not in
679 the proper format.
684 The \fBexec\fR functions may fail if:
686 .ne 2
688 \fB\fBENAMETOOLONG\fR\fR
690 .RS 16n
691 Pathname resolution of a symbolic link produced an intermediate result whose
692 length exceeds {\fBPATH_MAX\fR}.
696 .ne 2
698 \fB\fBENOMEM\fR\fR
700 .RS 16n
701 The new process image requires more memory than is allowed by the hardware or
702 system-imposed by memory management constraints. See \fBbrk\fR(2).
706 .ne 2
708 \fB\fBETXTBSY\fR\fR
710 .RS 16n
711 The new process image file is a pure procedure (shared text) file that is
712 currently open for writing by some process.
715 .SH USAGE
717 As the state of conversion descriptors and message catalogue descriptors in the
718 new process image is undefined, portable applications should not rely on their
719 use and should close them prior to calling one of the \fBexec\fR functions.
722 Applications that require other than the default POSIX locale should call
723 \fBsetlocale\fR(3C) with the appropriate parameters to establish the locale of
724 thenew process.
727 The \fIenviron\fR array should not be accessed directly by the application.
728 .SH ATTRIBUTES
730 See \fBattributes\fR(5) for descriptions of the following attributes:
735 box;
736 c | c
737 l | l .
738 ATTRIBUTE TYPE  ATTRIBUTE VALUE
740 Interface Stability     Committed
742 MT-Level        See below.
744 Standard        See \fBstandards\fR(5).
749 The \fBexecle()\fR and \fBexecve()\fR fucntions are Async-Signal-Safe.
750 .SH SEE ALSO
752 \fBksh\fR(1), \fBps\fR(1), \fBsh\fR(1), \fBalarm\fR(2), \fBbrk\fR(2),
753 \fBchmod\fR(2), \fBexit\fR(2), \fBfcntl\fR(2), \fBfork\fR(2),
754 \fBgetpflags\fR(2), \fBgetrlimit\fR(2), \fBmemcntl\fR(2), \fBmmap\fR(2),
755 \fBnice\fR(2), \fBpriocntl\fR(2), \fBprofil\fR(2), \fBsemop\fR(2),
756 \fBshmop\fR(2), \fBsigpending\fR(2), \fBsigprocmask\fR(2), \fBtimes\fR(2),
757 \fBumask\fR(2), \fBlockf\fR(3C), \fBptrace\fR(3C), \fBsetlocale\fR(3C),
758 \fBsignal\fR(3C), \fBsystem\fR(3C), \fBtimer_create\fR(3C), \fBa.out\fR(4),
759 \fBcontract\fR(4), \fBprocess\fR(4), \fBattributes\fR(5), \fBenviron\fR(5),
760 \fBprivileges\fR(5), \fBstandards\fR(5)
761 .SH WARNINGS
763 If a program is \fBsetuid\fR to a user \fBID\fR other than the superuser, and
764 the program is executed when the real user \fBID\fR is super-user, then the
765 program has some of the powers of a super-user as well.