blob: 1a0a8a87180977fb67499497aa1ec1607119b0ed [file] [log] [blame]
exec, execl \- execute a file
.B #include <u.h>
.B #include <libc.h>
int exec(char *name, char* argv[])
int execl(char *name, ...)
.I Exec
.I execl
overlay the calling process with the named file, then
transfer to the entry point of the image of the file.
.I Name
points to the name of the file
to be executed; it must not be a directory, and the permissions
must allow the current user to execute it
.IR stat (3)).
It should also be a valid binary image, as defined by the local
operating system, or a shell script
.IR rc (1)).
The first line of a
shell script must begin with
.L #!
followed by the name of the program to interpret the file
and any initial arguments to that program, for example
ls | mc
When a C program is executed,
it is called as follows:
void main(int argc, char *argv[])
.I Argv
is a copy of the array of argument pointers passed to
.IR exec ;
that array must end in a null pointer, and
.I argc
is the number of elements before the null pointer.
By convention, the first argument should be the name of
the program to be executed.
.I Execl
is like
.I exec
except that
.I argv
will be an array of the parameters that follow
.I name
in the call. The last argument to
.I execl
must be a null pointer.
For a file beginning
.BR #! ,
the arguments passed to the program
.RB ( /bin/rc
in the example above) will be the name of the file being
executed, any arguments on the
.B #!
line, the name of the file again,
and finally the second and subsequent arguments given to the original
.I exec
The result honors the two conventions of a program accepting as argument
a file to be interpreted and
.B argv[0]
naming the file being
Most attributes of the calling process are carried
into the result; in particular,
files remain open across
.I exec
(except those opened with
into the open mode; see
.IR open (3));
and the working directory and environment
.IR getenv (3))
remain the same.
However, a newly
.I exec'ed
process has no notification handlers
.IR notify (3)).
.B \*9/src/lib9/exec.c
.B \*9/src/lib9/execl.c
.IR prof (1),
.IR intro (3),
.IR stat (3)
If these functions fail, they return and set
.IR errstr .
There can be no return from a successful
.I exec
.IR execl ;
the calling image is lost.
On Unix, unlike on Plan 9,
.I exec
.I execl
use the user's current path to locate
.IR prog .
This is a clumsy way to deal with Unix's lack of
a union directory for
.BR /bin .
To avoid name conflicts with the underlying system,
.I exec
.I execl
are preprocessor macros defined as
.I p9exec
.IR p9execl ;
.IR intro (3).