blob: 1a0a8a87180977fb67499497aa1ec1607119b0ed [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH EXEC 3
2.SH NAME
rsc058b0112005-01-03 06:40:20 +00003exec, execl \- execute a file
rsccfa37a72004-04-10 18:53:55 +00004.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.nf
10.B
11int exec(char *name, char* argv[])
12.PP
13.B
14int execl(char *name, ...)
rsccfa37a72004-04-10 18:53:55 +000015.fi
16.SH DESCRIPTION
17.I Exec
18and
19.I execl
20overlay the calling process with the named file, then
21transfer to the entry point of the image of the file.
22.PP
23.I Name
24points to the name of the file
25to be executed; it must not be a directory, and the permissions
26must allow the current user to execute it
27(see
rscbf8a59f2004-04-11 03:42:27 +000028.IR stat (3)).
rsc058b0112005-01-03 06:40:20 +000029It should also be a valid binary image, as defined by the local
30operating system, or a shell script
rsccfa37a72004-04-10 18:53:55 +000031(see
32.IR rc (1)).
33The first line of a
34shell script must begin with
35.L #!
36followed by the name of the program to interpret the file
37and any initial arguments to that program, for example
38.IP
39.EX
40#!/bin/rc
41ls | mc
42.EE
43.PP
44When a C program is executed,
45it is called as follows:
46.IP
47.EX
48void main(int argc, char *argv[])
49.EE
50.PP
51.I Argv
52is a copy of the array of argument pointers passed to
53.IR exec ;
54that array must end in a null pointer, and
55.I argc
56is the number of elements before the null pointer.
57By convention, the first argument should be the name of
58the program to be executed.
59.I Execl
60is like
61.I exec
62except that
63.I argv
64will be an array of the parameters that follow
65.I name
66in the call. The last argument to
67.I execl
68must be a null pointer.
69.PP
70For a file beginning
71.BR #! ,
72the arguments passed to the program
73.RB ( /bin/rc
74in the example above) will be the name of the file being
75executed, any arguments on the
76.B #!
77line, the name of the file again,
78and finally the second and subsequent arguments given to the original
79.I exec
80call.
81The result honors the two conventions of a program accepting as argument
82a file to be interpreted and
83.B argv[0]
84naming the file being
85executed.
86.PP
87Most attributes of the calling process are carried
88into the result; in particular,
89files remain open across
90.I exec
91(except those opened with
92.B OCEXEC
93OR'd
94into the open mode; see
rscbf8a59f2004-04-11 03:42:27 +000095.IR open (3));
rsccfa37a72004-04-10 18:53:55 +000096and the working directory and environment
97(see
rsc058b0112005-01-03 06:40:20 +000098.IR getenv (3))
rsccfa37a72004-04-10 18:53:55 +000099remain the same.
100However, a newly
101.I exec'ed
rsc058b0112005-01-03 06:40:20 +0000102process has no notification handlers
rsccfa37a72004-04-10 18:53:55 +0000103(see
rscbf8a59f2004-04-11 03:42:27 +0000104.IR notify (3)).
rsccfa37a72004-04-10 18:53:55 +0000105.SH SOURCE
rscc3674de2005-01-11 17:37:33 +0000106.B \*9/src/lib9/exec.c
rsccfa37a72004-04-10 18:53:55 +0000107.br
rscc3674de2005-01-11 17:37:33 +0000108.B \*9/src/lib9/execl.c
rsccfa37a72004-04-10 18:53:55 +0000109.SH SEE ALSO
110.IR prof (1),
rscbf8a59f2004-04-11 03:42:27 +0000111.IR intro (3),
112.IR stat (3)
rsccfa37a72004-04-10 18:53:55 +0000113.SH DIAGNOSTICS
114If these functions fail, they return and set
115.IR errstr .
116There can be no return from a successful
117.I exec
118or
119.IR execl ;
120the calling image is lost.
rsc058b0112005-01-03 06:40:20 +0000121.SH BUGS
122On Unix, unlike on Plan 9,
123.I exec
124and
125.I execl
126use the user's current path to locate
127.IR prog .
128This is a clumsy way to deal with Unix's lack of
129a union directory for
130.BR /bin .
rscc8b63422005-01-13 04:49:19 +0000131.PP
132To avoid name conflicts with the underlying system,
133.I exec
134and
135.I execl
136are preprocessor macros defined as
137.I p9exec
138and
139.IR p9execl ;
140see
141.IR intro (3).