| <head> |
| <title>exec(3) - Plan 9 from User Space</title> |
| <meta content="text/html; charset=utf-8" http-equiv=Content-Type> |
| </head> |
| <body bgcolor=#ffffff> |
| <table border=0 cellpadding=0 cellspacing=0 width=100%> |
| <tr height=10><td> |
| <tr><td width=20><td> |
| <tr><td width=20><td><b>EXEC(3)</b><td align=right><b>EXEC(3)</b> |
| <tr><td width=20><td colspan=2> |
| <br> |
| <p><font size=+1><b>NAME </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| exec, execl – execute a file<br> |
| |
| </table> |
| <p><font size=+1><b>SYNOPSIS </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <tt><font size=+1>#include <u.h><br> |
| #include <libc.h> |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>int exec(char *name, char* argv[])<br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>int execl(char *name, ...)<br> |
| </font></tt> |
| </table> |
| <p><font size=+1><b>DESCRIPTION </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <i>Exec</i> and <i>execl</i> overlay the calling process with the named file, |
| then transfer to the entry point of the image of the file. |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| <i>Name</i> 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 (see <a href="../man3/stat.html"><i>stat</i>(3)</a>). It should also be a valid binary |
| image, as defined by the local operating system, or a shell script |
| (see <a href="../man1/rc.html"><i>rc</i>(1)</a>). The first line of a shell script must begin with |
| <tt><font size=+1>#!</font></tt> followed |
| by the name of the program to interpret the file and any initial |
| arguments to that program, for example<br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <tt><font size=+1>#!/bin/rc<br> |
| ls | mc<br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| |
| </table> |
| When a C program is executed, it is called as follows:<br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <tt><font size=+1>void main(int argc, char *argv[])<br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| |
| </table> |
| <i>Argv</i> is a copy of the array of argument pointers passed to <i>exec</i>; |
| that array must end in a null pointer, and <i>argc</i> 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</i> |
| is like <i>exec</i> except that <i>argv</i> will be an array of the parameters |
| that follow <i>name</i> in the call. The last argument to <i>execl</i> must |
| be a null pointer. |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| For a file beginning <tt><font size=+1>#!</font></tt>, the arguments passed to the program (<tt><font size=+1>/bin/rc</font></tt> |
| in the example above) will be the name of the file being executed, |
| any arguments on the <tt><font size=+1>#!</font></tt> line, the name of the file again, and |
| finally the second and subsequent arguments given to the original |
| <i>exec</i> call. The result honors the two conventions |
| of a program accepting as argument a file to be interpreted and |
| <tt><font size=+1>argv[0]</font></tt> naming the file being executed. |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| Most attributes of the calling process are carried into the result; |
| in particular, files remain open across <i>exec</i> (except those opened |
| with <tt><font size=+1>OCEXEC</font></tt> OR’d into the open mode; see <a href="../man3/open.html"><i>open</i>(3)</a>); and the working |
| directory and environment (see <a href="../man3/getenv.html"><i>getenv</i>(3)</a>) remain the same. However, |
| a newly <i>exec’ed</i> process has no notification |
| handlers (see <a href="../man3/notify.html"><i>notify</i>(3)</a>).<br> |
| |
| </table> |
| <p><font size=+1><b>SOURCE </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <tt><font size=+1>/usr/local/plan9/src/lib9/exec.c<br> |
| /usr/local/plan9/src/lib9/execl.c<br> |
| </font></tt> |
| </table> |
| <p><font size=+1><b>SEE ALSO </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| <a href="../man1/prof.html"><i>prof</i>(1)</a>, <a href="../man3/intro.html"><i>intro</i>(3)</a>, <a href="../man3/stat.html"><i>stat</i>(3)</a><br> |
| |
| </table> |
| <p><font size=+1><b>DIAGNOSTICS </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| If these functions fail, they return and set <i>errstr</i>. There can |
| be no return from a successful <i>exec</i> or <i>execl</i>; the calling image |
| is lost.<br> |
| |
| </table> |
| <p><font size=+1><b>BUGS </b></font><br> |
| |
| <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td> |
| |
| On Unix, unlike on Plan 9, <i>exec</i> and <i>execl</i> use the user’s current |
| path to locate <i>prog</i>. This is a clumsy way to deal with Unix’s |
| lack of a union directory for <tt><font size=+1>/bin</font></tt>. |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| |
| To avoid name conflicts with the underlying system, <i>exec</i> and <i>execl</i> |
| are preprocessor macros defined as <i>p9exec</i> and <i>p9execl</i>; see <a href="../man3/intro.html"><i>intro</i>(3)</a>.<br> |
| |
| </table> |
| |
| <td width=20> |
| <tr height=20><td> |
| </table> |
| <!-- TRAILER --> |
| <table border=0 cellpadding=0 cellspacing=0 width=100%> |
| <tr height=15><td width=10><td><td width=10> |
| <tr><td><td> |
| <center> |
| <a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a> |
| </center> |
| </table> |
| <!-- TRAILER --> |
| </body></html> |