aboutsummaryrefslogtreecommitdiff
path: root/man/man3/exec.html
blob: e53973520e4ccf6092c497d2ad368225f2faaf0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<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 &ndash; 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 &lt;u.h&gt;<br>
    #include &lt;libc.h&gt; 
    <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&#8217;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&#8217;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&#8217;s current
    path to locate <i>prog</i>. This is a clumsy way to deal with Unix&#8217;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>