aboutsummaryrefslogtreecommitdiff
path: root/man/man3/exec.3
blob: 488686169c8286d37f85a110e238e330a282bfef (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
147
148
149
150
151
152
153
154
155
156
157
158
159
.TH EXEC 3
.SH NAME
exec, execl, _clock, _privates, _nprivates \- execute a file
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.PP
.nf
.B
int exec(char *name, char* argv[])
.PP
.B
int execl(char *name, ...)
.PP
.B
long	*_clock;
.PP
.B
void	**_privates;
.PP
.B
int	_nprivates;
.fi
.SH DESCRIPTION
.I Exec
and
.I execl
overlay the calling process with the named file, then
transfer to the entry point of the image of the file.
.PP
.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
(see
.IR stat (3)).
It should also be a valid binary image, as defined in the
.IR a.out (6)
for the current machine architecture,
or a shell script
(see
.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
.IP
.EX
#!/bin/rc
ls | mc
.EE
.PP
When a C program is executed,
it is called as follows:
.IP
.EX
void main(int argc, char *argv[])
.EE
.PP
.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.
.PP
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
call.
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
executed.
.PP
Most attributes of the calling process are carried
into the result; in particular,
files remain open across
.I exec
(except those opened with
.B OCEXEC
OR'd
into the open mode; see
.IR open (3));
and the working directory and environment
(see
.IR env (3))
remain the same.
However, a newly
.I exec'ed
process has no notification handler
(see
.IR notify (3)).
.PP
When the new program begins, the global cell
.B _clock
is set to the address of a cell that keeps approximate time
expended by the process at user level.
The time is measured in milliseconds but is updated at
a system-dependent lower rate.
This clock is typically used by the profiler but is available
to all programs.
.PP
The global cell
.B _privates
points to an array of
.B _nprivates
elements of per-process private data.
This storage is private for each process, even if the processes share data segments.
.PP
The above conventions apply to C programs; the raw system
interface to the new image is as follows:
the word pointed to by the stack pointer is
.BR argc ;
the words beyond that are the zeroth and subsequent elements
of
.BR argv ,
followed by a terminating null pointer; and
the return register (e.g.
.B R0
on the 68020) contains the address of the clock.
.SH SOURCE
.B /usr/local/plan9/src/libc/9syscall
.br
.B /usr/local/plan9/src/libc/port/execl.c
.SH SEE ALSO
.IR prof (1),
.IR intro (3),
.IR stat (3)
.SH DIAGNOSTICS
If these functions fail, they return and set
.IR errstr .
There can be no return from a successful
.I exec
or
.IR execl ;
the calling image is lost.