122 lines
6.9 KiB
HTML
122 lines
6.9 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>execl(3)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<H1>execl(3)</H1>
|
|
<HR>
|
|
<PRE>
|
|
|
|
</PRE>
|
|
<H2>NAME</H2><PRE>
|
|
execl, execv, execle, execlp, execvp, exec, environ - execute a file
|
|
|
|
|
|
</PRE>
|
|
<H2>SYNOPSIS</H2><PRE>
|
|
<STRONG>#include</STRONG> <STRONG><unistd.h></STRONG>
|
|
|
|
<STRONG>int</STRONG> <STRONG>execl(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>name</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>arg0</EM><STRONG>,</STRONG> <STRONG>...,</STRONG> <STRONG>(char</STRONG> <STRONG>*)</STRONG> <STRONG>NULL)</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>execv(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>name</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>argv</EM><STRONG>[])</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>execle(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>name</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>arg0</EM><STRONG>,</STRONG> <STRONG>...,</STRONG> <STRONG>(char</STRONG> <STRONG>*)</STRONG> <STRONG>NULL,</STRONG> <STRONG>char</STRONG>
|
|
<STRONG>*const</STRONG> <EM>envp</EM><STRONG>[])</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>execlp(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>name</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>arg0</EM><STRONG>,</STRONG> <STRONG>...,</STRONG> <STRONG>(char</STRONG> <STRONG>*)</STRONG> <STRONG>NULL)</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>execvp(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>name</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>argv</EM><STRONG>[])</STRONG>
|
|
|
|
<STRONG>extern</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <STRONG>*environ;</STRONG>
|
|
|
|
|
|
</PRE>
|
|
<H2>DESCRIPTION</H2><PRE>
|
|
These routines provide various interfaces to the <STRONG>execve</STRONG> system call.
|
|
Refer to <STRONG><A HREF="../man2/execve.2.html">execve(2)</A></STRONG> for a description of their properties; only brief
|
|
descriptions are provided here.
|
|
|
|
<STRONG>Exec</STRONG> in all its forms overlays the calling process with the named file,
|
|
then transfers to the entry point of the core image of the file. There
|
|
can be no return from a successful exec; the calling core image is lost.
|
|
|
|
The <EM>name</EM> argument is a pointer to the name of the file to be executed.
|
|
The pointers <EM>arg</EM>[<EM>0</EM>], <EM>arg</EM>[<EM>1</EM>] ... address null-terminated strings.
|
|
Conventionally <EM>arg</EM>[<EM>0</EM>] is the name of the file.
|
|
|
|
Two interfaces are available. <STRONG>execl</STRONG> is useful when a known file with
|
|
known arguments is being called; the arguments to <STRONG>execl</STRONG> are the character
|
|
strings constituting the file and the arguments; the first argument is
|
|
conventionally the same as the file name (or its last component). A null
|
|
pointer argument must end the argument list. (Note that the <STRONG>execl*</STRONG>
|
|
functions are variable argument functions. This means that the type of
|
|
the arguments beyond <EM>arg0</EM> is not checked. So the null pointer requires
|
|
an explicit cast to type <STRONG>(char</STRONG> <STRONG>*)</STRONG> if not of that type already.)
|
|
|
|
The <STRONG>execv</STRONG> version is useful when the number of arguments is unknown in
|
|
advance; the arguments to <STRONG>execv</STRONG> are the name of the file to be executed
|
|
and a vector of strings containing the arguments. The last argument
|
|
string must be followed by a null pointer.
|
|
|
|
When a C program is executed, it is called as follows:
|
|
|
|
<STRONG>int</STRONG> <STRONG>main(int</STRONG> <EM>argc</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>argv</EM><STRONG>[],</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>envp</EM><STRONG>[]);</STRONG>
|
|
|
|
<STRONG>exit(main(</STRONG><EM>argc</EM><STRONG>,</STRONG> <EM>argv</EM><STRONG>,</STRONG> <EM>envp</EM><STRONG>));</STRONG>
|
|
|
|
|
|
|
|
where <EM>argc</EM> is the argument count and <EM>argv</EM> is an array of character
|
|
pointers to the arguments themselves. As indicated, <EM>argc</EM> is
|
|
conventionally at least one and the first member of the array points to a
|
|
string containing the name of the file.
|
|
|
|
<EM>Argv</EM> is directly usable in another <STRONG>execv</STRONG> because <EM>argv</EM>[<EM>argc</EM>] is 0.
|
|
|
|
<EM>Envp</EM> is a pointer to an array of strings that constitute the <EM>environment</EM>
|
|
of the process. Each string consists of a name, an "=", and a null-
|
|
terminated value. The array of pointers is terminated by a null pointer.
|
|
The shell <STRONG><A HREF="../man1/sh.1.html">sh(1)</A></STRONG> passes an environment entry for each global shell
|
|
variable defined when the program is called. See <STRONG><A HREF="../man7/environ.7.html">environ(7)</A></STRONG> for some
|
|
conventionally used names. The C run-time start-off routine places a
|
|
copy of <EM>envp</EM> in the global cell <STRONG>environ</STRONG>, which is used by <STRONG>execv</STRONG> and <STRONG>execl</STRONG>
|
|
to pass the environment to any subprograms executed by the current
|
|
program.
|
|
|
|
<STRONG>Execlp</STRONG> and <STRONG>execvp</STRONG> are called with the same arguments as <STRONG>execl</STRONG> and <STRONG>execv</STRONG>,
|
|
but duplicate the shell's actions in searching for an executable file in
|
|
a list of directories. The directory list is obtained from the
|
|
environment variable <STRONG>PATH</STRONG>. Under standard Minix, if a file is found that
|
|
is executable, but does not have the proper executable header then it is
|
|
assumed to be a shell script. <STRONG>Execlp</STRONG> and <STRONG>execvp</STRONG> execute <STRONG>/bin/sh</STRONG> to
|
|
interpret the script. Under Minix-vmd this does not happen, a script
|
|
must begin with <STRONG>#!</STRONG> and the full path name of the interpreter if it is to
|
|
be an executable script.
|
|
|
|
|
|
</PRE>
|
|
<H2>SEE ALSO</H2><PRE>
|
|
<STRONG><A HREF="../man2/execve.2.html">execve(2)</A></STRONG>, <STRONG><A HREF="../man2/fork.2.html">fork(2)</A></STRONG>, <STRONG><A HREF="../man7/environ.7.html">environ(7)</A></STRONG>, <STRONG><A HREF="../man1/sh.1.html">sh(1)</A></STRONG>.
|
|
|
|
|
|
</PRE>
|
|
<H2>DIAGNOSTICS</H2><PRE>
|
|
If the file cannot be found, if it is not executable, if it does not
|
|
start with a valid magic number (see <STRONG><A HREF="../man5/a.out.5.html">a.out(5)</A></STRONG>), if maximum memory is
|
|
exceeded, or if the arguments require too much space, a return
|
|
constitutes the diagnostic; the return value is -1 and <STRONG>errno</STRONG> is set as
|
|
for <STRONG>execve</STRONG>. Even for the super-user, at least one of the execute-
|
|
permission bits must be set for a file to be executed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
</BODY>
|
|
</HTML>
|