OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / execve.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\" and Copyright (c) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Modified by Michael Haardt <michael@moria.de>
27 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>:
29 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1999-11-12 by Urs Thuermann <urs@isnogud.escape.de>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\" 2006-09-04 Michael Kerrisk <mtk.manpages@gmail.com>
33 .\"     Added list of process attributes that are not preserved on exec().
34 .\" 2007-09-14 Ollie Wild <aaw@google.com>, mtk
35 .\"     Add text describing limits on command-line arguments + environment
36 .\"
37 .\" Japanese Version Copyright (c) 1996 TABATA Tomohira
38 .\"         all rights reserved.
39 .\" Translated 1996-07-04, TABATA Tomohira <loba@k2.t.u-tokyo.ac.jp>
40 .\" Updated 1997-12-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
41 .\" Updated 2001-08-17, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
42 .\" Updated 2005-02-05, Yuichi SATO <ysato444@yahoo.co.jp>
43 .\" Updated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
44 .\" Updated 2005-11-19, Akihiro MOTOKI
45 .\" Updated 2006-08-13, Akihiro MOTOKI, LDP v2.39
46 .\" Updated 2007-01-09, Akihiro MOTOKI, LDP v2.43
47 .\" Updated 2007-06-03, Akihiro MOTOKI, LDP v2.51
48 .\" Updated 2007-10-12, Akihiro MOTOKI, LDP v2.66
49 .\" Updated 2008-04-04, Akihiro MOTOKI, LDP v2.79
50 .\" Updated 2008-11-05, Akihiro MOTOKI, LDP v3.12
51 .\"
52 .TH EXECVE 2 2010-01-06 "Linux" "Linux Programmer's Manual"
53 .\"O .SH NAME
54 .SH Ì¾Á°
55 .\"O execve \- execute program
56 execve \- ¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤¹¤ë
57 .\"O .SH SYNOPSIS
58 .SH ½ñ¼°
59 .B #include <unistd.h>
60 .sp
61 .BI "int execve(const char *" filename ", char *const " argv "[], "
62 .br
63 .BI "           char *const " envp []);
64 .\"O .SH DESCRIPTION
65 .SH ÀâÌÀ
66 .\"O .BR execve ()
67 .\"O executes the program pointed to by \fIfilename\fP.
68 .\"O \fIfilename\fP must be either a binary executable, or a script
69 .\"O starting with a line of the form:
70 .BR execve ()
71 ¤Ï¡¢\fIfilename\fP ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤¿¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤¹¤ë¡£
72 \fIfilename\fP ¤Ï¡¢¥Ð¥¤¥Ê¥ê¼Â¹Ô·Á¼°¤«¡¢
73 °Ê²¼¤Î·Á¼°¤Î¹Ô¤Ç»Ï¤Þ¤ë¥¹¥¯¥ê¥×¥È¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
74
75 .in +4n
76 .nf
77 \fB#!\fP \fIinterpreter \fP[optional-arg]
78 .fi
79 .in
80
81 .\"O For details of the latter case, see "Interpreter scripts" below.
82 ¸å¼Ô¤Î¾ÜºÙ¤Ï¡¢¸å¤í¤Î¡Ö¥¤¥ó¥¿¥×¥ê¥¿¡¦¥¹¥¯¥ê¥×¥È¡×¤ÎÀá¤ò»²¾È¤Î¤³¤È¡£
83
84 .\"O \fIargv\fP is an array of argument strings passed to the new program.
85 .\"O \fIenvp\fP is an array of strings, conventionally of the form
86 .\"O \fBkey=value\fP, which are passed as environment to the new program.
87 .\"O Both \fIargv\fP and \fIenvp\fP must be terminated by a null pointer.
88 .\"O The argument vector and environment can be accessed by the
89 .\"O called program's main function, when it is defined as:
90 \fIargv\fP ¤Ï¿·¤·¤¤¥×¥í¥°¥é¥à¤ËÅϤµ¤ì¤ë°ú¤­¿ôʸ»úÎó¤ÎÇÛÎó¤Ç¤¢¤ë¡£
91 \fIenvp\fP ¤Ïʸ»úÎó¤ÎÇÛÎó¤Ç¤¢¤ê¡¢ÅÁÅýŪ¤Ë \fBkey=value\fP ¤Î·Á¼°¤ò
92 ¤·¤Æ¤ª¤ê¡¢¿·¤·¤¤¥×¥í¥°¥é¥à¤Î´Ä¶­ÊÑ¿ô¤È¤·¤ÆÅϤµ¤ì¤ë¡£
93 \fIargv\fP ¤È \fIenvp\fP ¤Ï¤¤¤º¤ì¤â¤Î NULL ¥Ý¥¤¥ó¥¿¤Ç½ª¤ï¤Ã¤Æ¤¤¤ë
94 ɬÍפ¬¤¢¤ë¡£°ú¤­¿ôÇÛÎó¤È´Ä¶­ÊÑ¿ô¤Ï¡¢¸Æ¤Ó½Ð¤µ¤ì¤¿¥×¥í¥°¥é¥à¤Î main ´Ø¿ô¤ò
95 °Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¥¢¥¯¥»¥¹²Äǽ¤Ë¤Ê¤ë¡£
96
97 .in +4n
98 .nf
99 int main(int argc, char *argv[], char *envp[])
100 .fi
101 .in
102
103 .\"O .BR execve ()
104 .\"O does not return on success, and the text, data, bss, and
105 .\"O stack of the calling process are overwritten by that of the program
106 .\"O loaded.
107 À®¸ù¤·¤¿¾ì¹ç¡¢
108 .BR execve ()
109 ¤ÏÊÖ¤é¤Ê¤¤¡£
110 ¤½¤·¤Æ¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î text, data, bss, ¥¹¥¿¥Ã¥¯¤Ï¡¢
111 Æɤ߹þ¤Þ¤ì¤¿¥×¥í¥°¥é¥à¤Ë¤è¤Ã¤Æ¾å½ñ¤­¤µ¤ì¤ë¡£
112
113 .\"O If the current program is being ptraced, a \fBSIGTRAP\fP is sent to it
114 .\"O after a successful
115 .\"O .BR execve ().
116 ¸µ¤Î¥×¥í¥°¥é¥à¤¬ ptrace ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
117 .BR execve ()
118 ¤¬À®¸ù¤·¤¿¸å¤Ë
119 ¤½¤Î¥×¥í¥°¥é¥à¤Ë \fBSIGTRAP\fP ¤¬Á÷¤é¤ì¤ë¡£
120
121 .\"O If the set-user-ID bit is set on the program file pointed to by
122 .\"O \fIfilename\fP,
123 .\"O and the underlying file system is not mounted
124 .\"O .I nosuid
125 .\"O (the
126 .\"O .B MS_NOSUID
127 .\"O flag for
128 .\"O .BR mount (2)),
129 .\"O and the calling process is not being ptraced,
130 .\"O then the effective user ID of the calling process is changed
131 .\"O to that of the owner of the program file.
132 .\"O Similarly, when the set-group-ID
133 .\"O bit of the program file is set the effective group ID of the calling
134 .\"O process is set to the group of the program file.
135 .I filename
136 ¤Ç»ØÄꤵ¤ì¤¿¥×¥í¥°¥é¥à¥Õ¥¡¥¤¥ë¤Ë set-user-ID ¥Ó¥Ã¥È¤¬ÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢
137 ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤¬
138 .I nosuid
139 .RB ( mount (2)
140 ¤Î
141 .B MS_NOSUID
142 ¥Õ¥é¥°) ¤Ç¥Þ¥¦¥ó¥È¤µ¤ì¤Æ¤ª¤é¤º¡¢
143 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤¬ ptrace ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
144 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¼Â¸ú (effective) ¥æ¡¼¥¶ ID ¤Ï
145 ¥×¥í¥°¥é¥à¥Õ¥¡¥¤¥ë¤Î½êÍ­¼Ô (owner) ¤ËÊѹ¹¤µ¤ì¤ë¡£
146 ƱÍͤˡ¢¥×¥í¥°¥é¥à¥Õ¥¡¥¤¥ë¤Ë set-group-ID ¥Ó¥Ã¥È¤¬ÀßÄꤵ¤ì¤Æ¤¤¤¿¾ì¹ç¡¢
147 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤ÎÍ­¸ú¥°¥ë¡¼¥× ID ¤Ï
148 ¥×¥í¥°¥é¥à¥Õ¥¡¥¤¥ë¤Î¥°¥ë¡¼¥×¤ËÊѹ¹¤µ¤ì¤ë¡£
149
150 .\"O The effective user ID of the process is copied to the saved set-user-ID;
151 .\"O similarly, the effective group ID is copied to the saved set-group-ID.
152 .\"O This copying takes place after any effective ID changes that occur
153 .\"O because of the set-user-ID and set-group-ID permission bits.
154 ¥×¥í¥»¥¹¤Î¼Â¸ú¥æ¡¼¥¶ ID ¤ÏÊݸ (saved) set-user-ID ¤Ë¥³¥Ô¡¼¤µ¤ì¤ë¡£
155 ƱÍͤˡ¢¼Â¸ú¥°¥ë¡¼¥× ID ¤ÏÊݸ set-group-ID ¤Ë¥³¥Ô¡¼¤µ¤ì¤ë¡£
156 ¤³¤Î¥³¥Ô¡¼¤Ï¡¢set-user-ID / set-group-ID µö²Ä¥Ó¥Ã¥È¤Ë¤è¤êȯÀ¸¤¹¤ë
157 ¼Â¸ú ID ¤ÎÊѹ¹¸å¤Ë¹Ô¤ï¤ì¤ë¡£
158
159 .\"O If the executable is an a.out dynamically linked
160 .\"O binary executable containing
161 .\"O shared-library stubs, the Linux dynamic linker
162 .\"O .BR ld.so (8)
163 .\"O is called at the start of execution to bring
164 .\"O needed shared libraries into memory
165 .\"O and link the executable with them.
166 ¼Â¹Ô¥Õ¥¡¥¤¥ë¤¬Æ°Åª¥ê¥ó¥¯¤µ¤ì¤¿ a.out ¼Â¹Ô·Á¼°¤Ç¡¢¶¦Í­¥é¥¤¥Ö¥é¥ê¤Î
167 ¥¹¥¿¥Ö¤ò´Þ¤à¤â¤Î¤À¤Ã¤¿¾ì¹ç¡¢¼Â¹Ô¤Î³«»Ï»þ¤Ë Linux ¤Î
168 ¥À¥¤¥Ê¥ß¥Ã¥¯¡¦¥ê¥ó¥«
169 .BR ld.so (8)
170 ¤¬¸Æ¤Ó½Ð¤µ¤ì¡¢É¬Íפʶ¦Í­¥é¥¤¥Ö¥é¥ê¤ò¥á¥â¥ê¤ËÆɤ߹þ¤ó¤Ç¥ê¥ó¥¯¤ò¹Ô¤¦¡£
171
172 .\"O If the executable is a dynamically linked ELF executable, the
173 .\"O interpreter named in the PT_INTERP segment is used to load the needed
174 .\"O shared libraries.
175 .\"O This interpreter is typically
176 .\"O \fI/lib/ld-linux.so.1\fP for binaries linked with the
177 .\"O Linux libc 5, or \fI/lib/ld-linux.so.2\fP for binaries linked with the
178 .\"O glibc 2.
179 ¼Â¹Ô¥Õ¥¡¥¤¥ë¤¬¥À¥¤¥Ê¥ß¥Ã¥¯¡¦¥ê¥ó¥¯¤µ¤ì¤¿ ELF ¼Â¹Ô·Á¼°¤À¤Ã¤¿¾ì¹ç¡¢
180 PT_INTERP ¥»¥°¥á¥ó¥È¤Ë»ØÄꤵ¤ì¤¿¥¤¥ó¥¿¥×¥ê¥¿¤¬É¬ÍפÊ
181 ¶¦Í­¥é¥¤¥Ö¥é¥ê (shared library) ¤òÆɤ߹þ¤à¤Î¤Ë»ÈÍѤµ¤ì¤ë¡£
182 Ä̾¥¤¥ó¥¿¥×¥ê¥¿¤È¤·¤Æ¤Ï¡¢
183 Linux libc 5 ¤ò¥ê¥ó¥¯¤·¤¿¥Ð¥¤¥Ê¥ê¤Î¾ì¹ç¤Ë¤Ï
184 \fI/lib/ld-linux.so.1\fP ¤¬¡¢
185 glibc 2 ¤ò¥ê¥ó¥¯¤·¤¿¥Ð¥¤¥Ê¥ê¤Î¾ì¹ç¤Ë¤Ï
186 \fI/lib/ld-linux.so.2\fP ¤¬»ÈÍѤµ¤ì¤ë¡£
187
188 .\"O All process attributes are preserved during an
189 .\"O .BR execve (),
190 .\"O except the following:
191 °Ê²¼¤Ë¼¨¤¹°Ê³°¤Î¤¹¤Ù¤Æ¤Î¥×¥í¥»¥¹Â°À­¤Ï
192 .BR execve ()
193 ¤ÎÁ°¸å¤ÇÊÝ»ý¤µ¤ì¤ë¡£
194 .IP *
195 .\"O The dispositions of any signals that are being caught are
196 .\"O reset to the default
197 .\"O .RB ( signal (7)).
198 Ê᪤µ¤ì¤¿¥·¥°¥Ê¥ë¤Î½èÍýÊýË¡ (disposition) ¤Ï
199 ¥Ç¥Õ¥©¥ë¥ÈÆ°ºî¤Ë¥ê¥»¥Ã¥È¤µ¤ì¤ë
200 .RB ( signal (7))¡£
201 .IP *
202 .\"O Any alternate signal stack is not preserved
203 .\"O .RB ( sigaltstack (2)).
204 ÂåÂØ¥·¥°¥Ê¥ë¥¹¥¿¥Ã¥¯¤Ï¤É¤ì¤âÊÝ»ý¤µ¤ì¤Ê¤¤
205 .RB ( sigaltstack (2))¡£
206 .IP *
207 .\"O Memory mappings are not preserved
208 .\"O .RB ( mmap (2)).
209 ¥á¥â¥ê¥Þ¥Ã¥Ô¥ó¥°¤ÏÊÝ»ý¤µ¤ì¤Ê¤¤
210 .RB ( mmap (2))¡£
211 .IP *
212 .\"O Attached System V shared memory segments are detached
213 .\"O .RB ( shmat (2)).
214 Éղ䵤줿 (attached) System V ¶¦Í­¥á¥â¥ê¥»¥°¥á¥ó¥È¤ÏʬΥ¤µ¤ì¤ë
215 .RB ( shmat (2))¡£
216 .IP *
217 .\"O POSIX shared memory regions are unmapped
218 .\"O .RB ( shm_open (3)).
219 POSIX ¶¦Í­¥á¥â¥êÎΰè¤Ï¥Þ¥Ã¥Ô¥ó¥°¤ò²ò½ü¤µ¤ì¤ë
220 .RB ( shm_open (3))¡£
221 .IP *
222 .\"O Open POSIX message queue descriptors are closed
223 .\"O .RB ( mq_overview (7)).
224 ¥ª¡¼¥×¥ó¤µ¤ì¤¿ POSIX ¥á¥Ã¥»¡¼¥¸¥­¥å¡¼¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¥¯¥í¡¼¥º¤µ¤ì¤ë
225 .RB ( mq_overview (7))¡£
226 .IP *
227 .\"O Any open POSIX named semaphores are closed
228 .\"O .RB ( sem_overview (7)).
229 ¥ª¡¼¥×¥ó¤µ¤ì¤¿ POSIX Ì¾Á°ÉÕ¤­¥»¥Þ¥Õ¥©¤Ï¤¤¤º¤ì¤â¥¯¥í¡¼¥º¤µ¤ì¤ë
230 .RB ( sem_overview (7))¡£
231 .IP *
232 .\"O POSIX timers are not preserved
233 .\"O .RB ( timer_create (2)).
234 POSIX ¥¿¥¤¥Þ¤ÏÊÝ»ý¤µ¤ì¤Ê¤¤
235 .RB ( timer_create (2))¡£
236 .IP *
237 .\"O Any open directory streams are closed
238 .\"O .RB ( opendir (3)).
239 ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥ê¥¹¥È¥ê¡¼¥à¤Ï¤¤¤º¤ì¤â¥¯¥í¡¼¥º¤µ¤ì¤ë
240 .RB ( opendir (3))¡£
241 .IP *
242 .\"O Memory locks are not preserved
243 .\"O .RB ( mlock (2),
244 .\"O .BR mlockall (2)).
245 ¥á¥â¥ê¥í¥Ã¥¯¤ÏÊÝ»ý¤µ¤ì¤Ê¤¤
246 .RB ( mlock (2),
247 .BR mlockall (2))¡£
248 .IP *
249 .\"O Exit handlers are not preserved
250 .\"O .RB ( atexit (3),
251 .\"O .BR on_exit (3)).
252 ½ªÎ» (exit) ¥Ï¥ó¥É¥é¤ÏÊÝ»ý¤µ¤ì¤Ê¤¤
253 .RB ( atexit (3),
254 .BR on_exit (3))¡£
255 .IP *
256 .\"O The floating-point environment is reset to the default (see
257 .\"O .BR fenv (3)).
258 ÉâÆ°¾®¿ôÅÀ´ØÏ¢¤Î´Ä¶­¤Ï¥Ç¥Õ¥©¥ë¥È¤Ë¥ê¥»¥Ã¥È¤µ¤ì¤ë
259 .RB ( fenv (3)
260 »²¾È)¡£
261 .PP
262 .\"O The process attributes in the preceding list are all specified
263 .\"O in POSIX.1-2001.
264 .\"O The following Linux-specific process attributes are also
265 .\"O not preserved during an
266 .\"O .BR execve ():
267 ¾åµ­¤Î¥ê¥¹¥È¤Î¥×¥í¥»¥¹Â°À­¤Ï¤¤¤º¤ì¤â POSIX.1-2001 ¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¡£
268 °Ê²¼¤Ë¼¨¤¹ Linux ¸ÇÍ­¤Î¥×¥í¥»¥¹Â°À­¤â
269 .BR execve ()
270 ¤ÎÁ°¸å¤ÇÊÝ»ý¤µ¤ì¤Ê¤¤¡£
271 .IP * 3
272 .\"O The
273 .\"O .BR prctl (2)
274 .\"O .B PR_SET_DUMPABLE
275 .\"O flag is set,
276 .\"O unless a set-user-ID or set-group ID program is being executed,
277 .\"O in which case it is cleared.
278 set-user-ID ¤« set-group-ID ¤µ¤ì¤¿¥×¥í¥°¥é¥à¤¬¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
279 .BR prctl (2)
280 ¤Î
281 .B PR_SET_DUMPABLE
282 ¥Õ¥é¥°¤Ï¥¯¥ê¥¢¤µ¤ì¤ë¡£¤½¤ì°Ê³°¤Î¾ì¹ç¡¢¤³¤Î¥Õ¥é¥°¤Ï¥»¥Ã¥È¤µ¤ì¤ë¡£
283 .IP *
284 .\"O The
285 .\"O .BR prctl (2)
286 .\"O .B PR_SET_KEEPCAPS
287 .\"O flag is cleared.
288 .BR prctl (2)
289 ¤Î
290 .B PR_SET_KEEPCAPS
291 ¥Õ¥é¥°¤Ï¥¯¥ê¥¢¤µ¤ì¤ë¡£
292 .IP *
293 .\"O The process name, as set by
294 .\"O .BR prctl (2)
295 .\"O .B PR_SET_NAME
296 .\"O (and displayed by
297 .\"O .IR "ps\ \-o comm" ),
298 .\"O is reset to the name of the new executable file.
299 ¥×¥í¥»¥¹Ì¾¤Ï¿·¤·¤¤¼Â¹Ô¥Õ¥¡¥¤¥ë¤Î̾Á°¤Ë¥ê¥»¥Ã¥È¤µ¤ì¤ë¡£
300 ¥×¥í¥»¥¹Ì¾¤Ï
301 .BR prctl (2)
302 ¤Î
303 .B PR_SET_NAME
304 ¤ÇÀßÄê¤Ç¤­¡¢
305 .I "ps\ \-o comm"
306 ¤Çɽ¼¨¤Ç¤­¤ë¡£
307 .IP *
308 .\"O The termination signal is reset to
309 .\"O .B SIGCHLD
310 .\"O (see
311 .\"O .BR clone (2)).
312 ½ªÎ»¥·¥°¥Ê¥ë (termination signal) ¤Ï
313 .B SIGCHLD
314 ¤Ë¥ê¥»¥Ã¥È¤µ¤ì¤ë
315 .RB ( clone (2)
316 »²¾È)¡£
317 .PP
318 .\"O Note the following further points:
319 °Ê²¼¤ÎÅÀ¤Ë¤Ä¤¤¤Æ¤âÃí°Õ¤¹¤ë¤³¤È:
320 .IP * 3
321 .\"O All threads other than the calling thread are destroyed during an
322 .\"O .BR execve ().
323 .\"O Mutexes, condition variables, and other pthreads objects are not preserved.
324 ¸Æ¤Ó½Ð¤·¸µ¥¹¥ì¥Ã¥É°Ê³°¤ÎÁ´¤Æ¤Î¥¹¥ì¥Ã¥É¤Ï
325 .BR execve ()
326 Ãæ¤ËÇË´þ¤µ¤ì¤ë¡£
327 mutex¡¢¾ò·ïÊÑ¿ô¡¢¤½¤Î¾¤Î pthread ¥ª¥Ö¥¸¥§¥¯¥È¤ÏÊÝ»ý¤µ¤ì¤Ê¤¤¡£
328 .IP *
329 .\"O The equivalent of \fIsetlocale(LC_ALL, "C")\fP
330 .\"O is executed at program start-up.
331 \fIsetlocale(LC_ALL, "C")\fP ÁêÅö¤Î½èÍý¤¬¥×¥í¥°¥é¥à³«»Ï»þ¤Ë¼Â¹Ô¤µ¤ì¤ë¡£
332 .IP *
333 .\"O POSIX.1-2001 specifies that the dispositions of any signals that
334 .\"O are ignored or set to the default are left unchanged.
335 .\"O POSIX.1-2001 specifies one exception: if
336 .\"O .B SIGCHLD
337 .\"O is being ignored,
338 .\"O then an implementation may leave the disposition unchanged or
339 .\"O reset it to the default; Linux does the former.
340 POSIX.1-2001 ¤Ï¡¢Æ°ºî¤¬Ìµ»ë¤«¥Ç¥Õ¥©¥ë¥È¤ËÀßÄꤵ¤ì¤Æ¤¤¤ëÁ´¤Æ¤Î¥·¥°¥Ê¥ë
341 ¤Î½èÍýÊýË¡¤ÏÊѹ¹¤»¤º¤½¤Î¤Þ¤Þ¤Ë¤¹¤ë¡¢¤Èµ¬Äꤷ¤Æ¤¤¤ë¡£
342 ⤷¡¢POSIX.1-2001 ¤Ë¤Ï°ì¤ÄÎã³°¤¬¤¢¤ê¡¢
343 .B SIGCHLD
344 ¤¬Ìµ»ë¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢
345 ¤½¤Î½èÍýÊýË¡¤òÊѹ¹¤»¤º¤Ë¤½¤Î¤Þ¤Þ¤Ë¤¹¤ë¤«¡¢¥Ç¥Õ¥©¥ë¥ÈÆ°ºî¤Ë¥ê¥»¥Ã¥È¤¹¤ë¤«¤Ï
346 ¼ÂÁõ°Í¸¤È¤Ê¤Ã¤Æ¤¤¤ë¡£
347 Linux ¤Ç¤ÏÁ°¼Ô (Êѹ¹¤·¤Ê¤¤) ¤È¤Ê¤Ã¤Æ¤¤¤ë¡£
348 .IP *
349 .\"O Any outstanding asynchronous I/O operations are canceled
350 .\"O .RB ( aio_read (3),
351 .\"O .BR aio_write (3)).
352 ´°Î»¤·¤Æ¤¤¤Ê¤¤ÈóƱ´ü I/O Áàºî¤Ï¥­¥ã¥ó¥»¥ë¤µ¤ì¤ë
353 .RB ( aio_read (3),
354 .BR aio_write (3))¡£
355 .IP *
356 .\"O For the handling of capabilities during
357 .\"O .BR execve (),
358 .\"O see
359 .\"O .BR capabilities (7).
360 .BR execve (2)
361 »þ¤Î¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£¤Î°·¤¤¤Ë¤Ä¤¤¤Æ¤Ï¡¢
362 .BR capabilities (7)
363 ¤ò»²¾È¡£
364 .IP *
365 .\"O By default, file descriptors remain open across an
366 .\"O .BR execve ().
367 .\"O File descriptors that are marked close-on-exec are closed;
368 .\"O see the description of
369 .\"O .B FD_CLOEXEC
370 .\"O in
371 .\"O .BR fcntl (2).
372 .\"O (If a file descriptor is closed, this will cause the release
373 .\"O of all record locks obtained on the underlying file by this process.
374 .\"O See
375 .\"O .BR fcntl (2)
376 .\"O for details.)
377 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï
378 .BR execve ()
379 ¤ò¹Ô¤Ã¤¿¸å¤Ç¤â¥ª¡¼¥×¥ó¤µ¤ì¤¿¤Þ¤Þ¤Ç¤¢¤ë¡£
380 close-on-exec ¤Î°õ¤¬ÉÕ¤¤¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¥¯¥í¡¼¥º¤µ¤ì¤ë¡£
381 .BR fcntl (2)
382 ¤Î
383 .B FD_CLOEXEC
384 ¤ÎÀâÌÀ¤ò»²¾È¡£
385 (¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬¥¯¥í¡¼¥º¤µ¤ì¤ë¤È¡¢¤³¤Î¥×¥í¥»¥¹¤¬
386 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂбþ¤¹¤ë¥Õ¥¡¥¤¥ë¤ËÂФ·¤Æ³ÍÆÀ¤·¤Æ¤¤¤¿
387 ¥ì¥³¡¼¥É¤Î¥í¥Ã¥¯¤¬Á´¤Æ²òÊü¤µ¤ì¤ë¤³¤È¤Ë¤Ê¤ë¡£)
388 .\"O POSIX.1-2001 says that if file descriptors 0, 1, and 2 would
389 .\"O otherwise be closed after a successful
390 .\"O .BR execve (),
391 .\"O and the process would gain privilege because the set-user_ID or
392 .\"O set-group_ID permission bit was set on the executed file,
393 .\"O then the system may open an unspecified file for each of these
394 .\"O file descriptors.
395 .\"O As a general principle, no portable program, whether privileged or not,
396 .\"O can assume that these three file descriptors will remain
397 .\"O closed across an
398 .\"O .BR execve ().
399 POSIX.1-2001 ¤Ç¤Ï¡¢
400 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿ 0, 1, 2 ¤¬
401 .BR execve ()
402 À®¸ù¸å¤Ë¤É¤³¤«¤Ç¥¯¥í¡¼¥º¤µ¤ì¡¢¤«¤Ä
403 ¼Â¹Ô¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤Ë set-user_ID ¤« set-group_ID ¤Îµö²Ä¥Ó¥Ã¥È¤¬
404 ¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Æ¥×¥í¥»¥¹¤¬Æø¢¤ò³ÍÆÀ¤·¤¿¾ì¹ç¡¢
405 ¥·¥¹¥Æ¥à¤Ï²¿¤é¤«¤Î¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤¹¤ëºÝ¤Ë
406 ¤³¤ì¤é¤ÎÈÖ¹æ¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤É¤ì¤«¤ò»È¤¦¤³¤È¤¬¤¢¤ë¡¢
407 ¤È¤µ¤ì¤Æ¤¤¤ë¡£
408 ¸¶Â§¤È¤·¤Æ¡¢°Ü¿¢À­¤¬É¬Í×¤Ê¥×¥í¥°¥é¥à¤Ç¤Ï¡¢
409 Æø¢¤Î̵ͭ¤Ë´Ø¤ï¤é¤º¡¢
410 .BR execve ()
411 ¤ÎÁ°¸å¤Ç¤³¤ì¤é 3¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬¥¯¥í¡¼¥º¤µ¤ì¤¿¤Þ¤Þ¤Ç
412 ¤¢¤ë¤³¤È¤òÁ°Äó¤Ë¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£
413 .\" On Linux it appears that these file descriptors are
414 .\" always open after an execve(), and it looks like
415 .\" Solaris 8 and FreeBSD 6.1 are the same. -- mtk, 30 Apr 2007
416 .\"O .SS Interpreter scripts
417 .SS ¥¤¥ó¥¿¥×¥ê¥¿¡¦¥¹¥¯¥ê¥×¥È
418 .\"O An interpreter script is a text file that has execute
419 .\"O permission enabled and whose first line is of the form:
420 ¥¤¥ó¥¿¥×¥ê¥¿¡¦¥¹¥¯¥ê¥×¥È¤È¤Ï¡¢¼Â¹Ôµö²Ä¤¬Í­¸ú¤Ë¤Ê¤Ã¤Æ¤¤¤Æ¡¢
421 ºÇ½é¤Î¹Ô¤¬°Ê²¼¤Î·Á¤Ë¤Ê¤Ã¤Æ¤¤¤ë¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤Î¤³¤È¤Ç¤¢¤ë¡£
422
423 .in +4n
424 .nf
425 \fB#!\fP \fIinterpreter \fP[optional-arg]
426 .fi
427 .in
428
429 .\"O The
430 .\"O .I interpreter
431 .\"O must be a valid pathname for an
432 .\"O executable which is not itself a script.
433 .I interpreter
434 ¤ÏÍ­¸ú¤Ê¼Â¹Ô¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹Ì¾¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢
435 ¤½¤ì¼«¿È¤¬¥¹¥¯¥ê¥×¥È¤Ç¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
436 .\"O If the
437 .\"O .I filename
438 .\"O argument of
439 .\"O .BR execve ()
440 .\"O specifies an interpreter script, then
441 .\"O .I interpreter
442 .\"O will be invoked with the following arguments:
443 .BR execve ()
444 ¤Î
445 .I filename
446 °ú¤­¿ô¤¬¥¤¥ó¥¿¥×¥ê¥¿¥¹¥¯¥ê¥×¥È¤ò»ØÄꤷ¤Æ¤¤¤ë¾ì¹ç¡¢
447 .I interpreter
448 ¤Ï°Ê²¼¤Î°ú¤­¿ô¤Çµ¯Æ°¤µ¤ì¤ë¡£
449
450 .in +4n
451 .nf
452 \fIinterpreter\fP [optional-arg] \fIfilename\fP arg...
453 .fi
454 .in
455
456 .\"O where
457 .\"O .I arg...
458 .\"O is the series of words pointed to by the
459 .\"O .I argv
460 .\"O argument of
461 .\"O .BR execve ().
462 .I arg...
463 ¤Ï
464 .BR execve ()
465 ¤Î
466 .I argv
467 °ú¤­¿ô¤¬»Ø¤¹¥ï¡¼¥ÉÎó¤Ç¤¢¤ë¡£
468
469 .\"O For portable use,
470 .\"O .I optional-arg
471 .\"O should either be absent, or be specified as a single word (i.e., it
472 .\"O should not contain white space); see NOTES below.
473 °Ü¿¢À­¤ò»ý¤¿¤¹¤Ë¤Ï¡¢
474 .I optional-arg
475 ¤Ï¶õ¤« 1¥ï¡¼¥É¤À¤±¤Ë¤¹¤Ù¤­¤Ç¤¢¤ë
476 (¤Ä¤Þ¤ê¡¢¥Û¥ï¥¤¥È¡¦¥¹¥Ú¡¼¥¹¤ò´Þ¤á¤ë¤Ù¤­¤Ç¤Ï¤Ê¤¤)¡£
477 ²¼µ­¤Î¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È¡£
478 .\"O .SS "Limits on size of arguments and environment"
479 .SS "°ú¤­¿ô¤È´Ä¶­ÊÑ¿ô¤Î¹ç·×¥µ¥¤¥º¤Î¾å¸Â"
480 .\"O Most Unix implementations impose some limit on the total size
481 .\"O of the command-line argument
482 .\"O .RI ( argv )
483 .\"O and environment
484 .\"O .RI ( envp )
485 .\"O strings that may be passed to a new program.
486 .\"O POSIX.1 allows an implementation to advertise this limit using the
487 .\"O .B ARG_MAX
488 .\"O constant (either defined in
489 .\"O .I <limits.h>
490 .\"O or available at run time using the call
491 .\"O .IR "sysconf(_SC_ARG_MAX)" ).
492 ¤Û¤È¤ó¤É¤Î Unix ¤Î¼ÂÁõ¤Ï¡¢¿·¤·¤¤¥×¥í¥°¥é¥à¤ËÅϤ¹¤³¤È¤¬¤Ç¤­¤ë
493 ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô
494 .RI ( argv )
495 ¤È´Ä¶­ÊÑ¿ô
496 .RI ( envp )
497 ¤Îʸ»úÎ󷲤ιç·×¥µ¥¤¥º¤Ë²¿¤é¤«¤Î¾å¸Â¤òÀߤ±¤Æ¤¤¤ë¡£
498 POSIX.1 ¤Ï¡¢
499 .B ARG_MAX
500 Äê¿ô¤ò»È¤Ã¤Æ¤³¤Î¾å¸Â¤ò·è¤á¤ë¼ÂÁõ¤òǧ¤á¤Æ¤¤¤ë
501 .RB ( ARG_MAX
502 ¤Ï
503 .I <limits.h>
504 ¤ÇÄêµÁ¤µ¤ì¤ë¤«¡¢¼Â¹Ô»þ¤Ë
505 .I "sysconf(_SC_ARG_MAX)"
506 ¤Î¸Æ¤Ó½Ð¤·¤ÇÆþ¼ê¤Ç¤­¤ë¤«¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë)¡£
507
508 .\"O On Linux prior to kernel 2.6.23, the memory used to store the
509 .\"O environment and argument strings was limited to 32 pages
510 .\"O (defined by the kernel constant
511 .\"O .BR MAX_ARG_PAGES ).
512 .\"O On architectures with a 4-kB page size,
513 .\"O this yields a maximum size of 128 kB.
514 ¥«¡¼¥Í¥ë 2.6.23 ¤è¤êÁ°¤Î Linux ¤Ç¤Ï¡¢´Ä¶­ÊÑ¿ô¤È°ú¤­¿ô¤Îʸ»úÎ󷲤ò
515 ³ÊǼ¤¹¤ë¤Î¤Ë»ÈÍѤµ¤ì¤ë¥á¥â¥ê¤Ï 32 ¥Ú¡¼¥¸¤ËÀ©¸Â¤µ¤ì¤Æ¤¤¤¿
516 (32 ¥Ú¡¼¥¸¤È¤¤¤¦¤Î¤Ï¥«¡¼¥Í¥ëÄê¿ô
517 .B MAX_ARG_PAGES
518 ¤ÇÄêµÁ¤µ¤ì¤ë)¡£¤·¤¿¤¬¤Ã¤Æ¡¢
519 ¥Ú¡¼¥¸¥µ¥¤¥º¤¬ 4 kB ¤Î¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç¤Ï¡¢
520 ºÇÂ祵¥¤¥º¤Ï 128 kB ¤È¤¤¤¦¤³¤È¤Ë¤Ê¤ë¡£
521
522 .\"O On kernel 2.6.23 and later, most architectures support a size limit
523 .\"O derived from the soft
524 .\"O .B RLIMIT_STACK
525 .\"O resource limit (see
526 .\"O .BR getrlimit (2))
527 .\"O that is in force at the time of the
528 .\"O .BR execve ()
529 .\"O call.
530 ¥«¡¼¥Í¥ë 2.6.23 °Ê¹ß¤Ç¤Ï¡¢¤Û¤È¤ó¤É¤Î¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ë¤ª¤¤¤Æ¡¢
531 .BR execve ()
532 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿»þÅÀ¤ÇŬÍѤµ¤ì¤Æ¤¤¤ë¥ê¥½¡¼¥¹¤Î¥½¥Õ¥È¾å¸Â
533 .B RLIMIT_STACK
534 ¤Ë´ð¤Å¤¤¤¿¥µ¥¤¥º¾å¸Â¤¬»È¤ï¤ì¤ë
535 .\"O (Architectures with no memory management unit are excepted:
536 .\"O they maintain the limit that was in effect before kernel 2.6.23.)
537 .\"O This change allows programs to have a much larger
538 .\"O argument and/or environment list.
539 (¥á¥â¥ê´ÉÍý¥æ¥Ë¥Ã¥È (MMU) ¤ò»ý¤¿¤Ê¤¤¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ï¾åµ­¤ÎÊѹ¹¤Î
540 Îã³°¤Ç¤¢¤ê¡¢¤³¤ì¤é¤Î¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç¤Ï¥«¡¼¥Í¥ë 2.6.23 ¤è¤êÁ°¤È
541 Ʊ¤¸¾å¸Â¤¬¤½¤Î¤Þ¤Þ»ÈÍѤµ¤ì¤ë)¡£
542 .\" For some background on the changes to ARG_MAX in kernels 2.6.23 and
543 .\" 2.6.25, see:
544 .\"     http://sourceware.org/bugzilla/show_bug.cgi?id=5786
545 .\"     http://bugzilla.kernel.org/show_bug.cgi?id=10095
546 .\"     http://thread.gmane.org/gmane.linux.kernel/646709/focus=648101,
547 .\"     checked into 2.6.25 as commit a64e715fc74b1a7dcc5944f848acc38b2c4d4ee2.
548 .\"O For these architectures, the total size is limited to 1/4 of the allowed
549 .\"O stack size.
550 .\"O (Imposing the 1/4-limit
551 .\"O ensures that the new program always has some stack space.)
552 ¤³¤ì¤é¤Î¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç¤Ï¡¢¹ç·×¥µ¥¤¥º¤Ïµö²Ä¤µ¤ì¤¿¥¹¥¿¥Ã¥¯¥µ¥¤¥º¤Î
553 1/4 ¤ËÀ©¸Â¤µ¤ì¤Æ¤¤¤ë
554 (1/4 ¤Î¾å¸Â¤òÀߤ±¤Æ¤¤¤ë¤Î¤Ï¡¢¿·¤·¤¤¥×¥í¥°¥é¥à¤¬É¬¤º¤¢¤ëÄøÅÙ¤Î
555 ¥¹¥¿¥Ã¥¯¶õ´Ö¤ò»ý¤Æ¤ë¤³¤È¤òÊݾڤ¹¤ë¤¿¤á¤Ç¤¢¤ë)¡£
556 .\" Ollie: That doesn't include the lists of pointers, though,
557 .\" so the actual usage is a bit higher (1 pointer per argument).
558 .\"O Since Linux 2.6.25,
559 .\"O the kernel places a floor of 32 pages on this size limit,
560 .\"O so that, even when
561 .\"O .BR RLIMIT_STACK
562 .\"O is set very low,
563 .\"O applications are guaranteed to have at least as much argument and
564 .\"O environment space as was provided by Linux 2.6.23 and earlier.
565 .\"O (This guarantee was not provided in Linux 2.6.23 and 2.6.24.)
566 Linux 2.6.25 °Ê¹ß¤Ç¤Ï¡¢¥«¡¼¥Í¥ë¤Ï¤³¤Î¥µ¥¤¥º¾å¸Â¤Ë 32 ¥Ú¡¼¥¸¤Î²¼¸Â¤ò
567 Àߤ±¤Æ¤¤¤ë¡£¤³¤ì¤Ë¤è¤ê¡¢
568 .B RLIMIT_STACK
569 ¤¬Èó¾ï¤Ë¾®¤µ¤¯ÀßÄꤵ¤ì¤¿¾ì¹ç¤Ç¤â¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¾¯¤Ê¤¯¤È¤â
570 Linux 2.6.23 °ÊÁ°¤ÇÄ󶡤µ¤ì¤Æ¤¤¤¿¤Î¤ÈƱ¤¸Â礭¤µ¤Î°ú¤­¿ô¤È´Ä¶­ÊÑ¿ô¤Î¶õ´Ö
571 ¤ÈƱ¤¸¤À¤±¤Ï³ÎÊݤǤ­¤ë¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤ë
572 (¤³¤ÎºÇÄã¸Â¤ÎÊݾڤϠLinux 2.6.23 ¤È 2.6.24 ¤Ç¤ÏÄ󶡤µ¤ì¤Æ¤¤¤Ê¤¤)¡£
573 .\"O Additionally, the limit per string is 32 pages (the kernel constant
574 .\"O .BR MAX_ARG_STRLEN ),
575 .\"O and the maximum number of strings is 0x7FFFFFFF.
576 ¤Þ¤¿¡¢³Æʸ»úÎó¤Î¾å¸Â¤Ï 32 ¥Ú¡¼¥¸ (¥«¡¼¥Í¥ëÄê¿ô
577 .BR MAX_ARG_STRLEN )
578 ¤Ç¡¢Ê¸»úÎó¿ô¤ÎºÇÂçÃͤϠ0x7FFFFFFF ¤Ç¤¢¤ë¡£
579 .\"O .SH "RETURN VALUE"
580 .SH ÊÖ¤êÃÍ
581 .\"O On success,
582 .\"O .BR execve ()
583 .\"O does not return, on error \-1 is returned, and
584 .\"O .I errno
585 .\"O is set appropriately.
586 À®¸ù¤¹¤ë¤È
587 .BR execve ()
588 ¤ÏÊÖ¤é¤Ê¤¤¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï \-1 ¤òÊÖ¤·¡¢
589 .I errno
590 ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
591 .\"O .SH ERRORS
592 .SH ¥¨¥é¡¼
593 .TP
594 .B E2BIG
595 .\"O The total number of bytes in the environment
596 .\"O .RI ( envp )
597 .\"O and argument list
598 .\"O .RI ( argv )
599 .\"O is too large.
600 ´Ä¶­ÊÑ¿ô
601 .RI ( envp )
602 ¤È°ú¤­¿ô¥ê¥¹¥È
603 .RI ( argv )
604 ¤Î¹ç·×¥Ð¥¤¥È¿ô¤¬Â礭²á¤®¤ë¡£
605 .TP
606 .B EACCES
607 .\"O Search permission is denied on a component of the path prefix of
608 .\"O .I filename
609 .\"O or the name of a script interpreter.
610 .\"O (See also
611 .\"O .BR path_resolution (7).)
612 .I filename
613 ¤ä¥¹¥¯¥ê¥×¥È¥¤¥ó¥¿¥×¥ê¥¿Ì¾¤Î¹½À®Í×ÁǤ˸¡º÷µö²Ä (search permission)
614 ¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤
615 .RB ( path_resolution (7)
616 ¤â»²¾È¤¹¤ë¤³¤È)¡£
617 .TP
618 .B EACCES
619 .\"O The file or a script interpreter is not a regular file.
620 ¥Õ¥¡¥¤¥ë¤â¤·¤¯¤Ï¥¹¥¯¥ê¥×¥È¤Î¥¤¥ó¥¿¥×¥ê¥¿¤¬Ä̾ï¥Õ¥¡¥¤¥ë (regular file)
621 ¤Ç¤Ê¤¤¡£
622 .TP
623 .B EACCES
624 .\"O Execute permission is denied for the file or a script or ELF interpreter.
625 ¥Õ¥¡¥¤¥ë¤ä¥¹¥¯¥ê¥×¥È¤ä ELF ¥¤¥ó¥¿¥×¥ê¥¿¤Ë
626 ¼Â¹Ôµö²Ä (execute permission) ¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤¡£
627 .TP
628 .B EACCES
629 .\"O The file system is mounted
630 .\"O .IR noexec .
631 ¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¤¬
632 .I noexec
633 ¤Ç¥Þ¥¦¥ó¥È¤µ¤ì¤Æ¤¤¤ë¡£
634 .TP
635 .B EFAULT
636 .\"O .I filename
637 .\"O points outside your accessible address space.
638 .I filename
639 ¤¬¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö¤Î³°¤ò»Ø¤·¤Æ¤¤¤ë¡£
640 .TP
641 .B EINVAL
642 .\"O An ELF executable had more than one PT_INTERP segment (i.e., tried to
643 .\"O name more than one interpreter).
644 ELF ¼Â¹Ô·Á¼°¤ÇÊ£¿ô¤Î PT_INTERP ¥»¥°¥á¥ó¥È¤¬Â¸ºß¤¹¤ë¡£
645 (¤¹¤Ê¤ï¤ÁÊ£¿ô¤Î¥¤¥ó¥¿¥×¥ê¥¿¤ò»ØÄꤷ¤¿¡£)
646 .TP
647 .B EIO
648 .\"O An I/O error occurred.
649 I/O ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¡£
650 .TP
651 .B EISDIR
652 .\"O An ELF interpreter was a directory.
653 ELF ¥¤¥ó¥¿¥×¥ê¥¿¤¬¥Ç¥£¥ì¥¯¥È¥ê¤À¤Ã¤¿¡£
654 .TP
655 .B ELIBBAD
656 .\"O An ELF interpreter was not in a recognized format.
657 ELF ¥¤¥ó¥¿¥×¥ê¥¿¤¬Íý²ò¤Ç¤­¤ë¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¤Ê¤«¤Ã¤¿¡£
658 .TP
659 .B ELOOP
660 .\"O Too many symbolic links were encountered in resolving
661 .\"O .I filename
662 .\"O or the name of a script or ELF interpreter.
663 .I filename
664 ¤ä¥¹¥¯¥ê¥×¥È¤ä ELF ¤Î¥¤¥ó¥¿¥×¥ê¥¿¤ò²ò·è¤¹¤ëºÝ¤ËÁø¶ø¤·¤¿
665 ¥·¥ó¥Ü¥ê¥Ã¥¯¡¦¥ê¥ó¥¯¤¬Â¿²á¤®¤ë¡£
666 .TP
667 .B EMFILE
668 .\"O The process has the maximum number of files open.
669 ¤½¤Î¥×¥í¥»¥¹¤¬¥ª¡¼¥×¥ó¤Ç¤­¤ë¥Õ¥¡¥¤¥ë¿ô¤Î¾å¸Â¤Þ¤Ç´û¤Ë¥ª¡¼¥×¥ó¤·¤Æ¤¤¤ë¡£
670 .TP
671 .B ENAMETOOLONG
672 .\"O .I filename
673 .\"O is too long.
674 .I filename
675 ¤¬Ä¹²á¤®¤ë¡£
676 .TP
677 .B ENFILE
678 .\"O The system limit on the total number of open files has been reached.
679 ¤½¤Î¥·¥¹¥Æ¥à¤Ç¥ª¡¼¥×¥ó¤Ç¤­¤ë¥Õ¥¡¥¤¥ë¿ô¤ÎÀ©¸Â¤Ë㤷¤¿¡£
680 .TP
681 .B ENOENT
682 .\"O The file
683 .\"O .I filename
684 .\"O or a script or ELF interpreter does not exist, or a shared library
685 .\"O needed for file or interpreter cannot be found.
686 ¥Õ¥¡¥¤¥ë
687 .I filename
688 ¤«¥¹¥¯¥ê¥×¥È¤ä ELF ¤Î¥¤¥ó¥¿¥×¥ê¥¿¤¬Â¸ºß¤·¤Ê¤¤¡£
689 .TP
690 .B ENOEXEC
691 .\"O An executable is not in a recognized format, is for the wrong
692 .\"O architecture, or has some other format error that means it cannot be
693 .\"O executed.
694 ¼Â¹Ô¥Õ¥¡¥¤¥ë¤¬Íý²ò¤Ç¤­¤Ê¤¤·Á¼°¤Ç¤¢¤ë¤«¡¢°ã¤¦¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Î¤â¤Î¤«¡¢
695 ¤½¤Î¾¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¡¦¥¨¥é¡¼¤Ë¤è¤ê¼Â¹Ô¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¡£
696 .TP
697 .B ENOMEM
698 .\"O Insufficient kernel memory was available.
699 ¥«¡¼¥Í¥ë¤Ë½½Ê¬¤Ê¥á¥â¥ê¤¬¤Ê¤¤¡£
700 .TP
701 .B ENOTDIR
702 .\"O A component of the path prefix of
703 .\"O .I filename
704 .\"O or a script or ELF interpreter is not a directory.
705 .I filename
706 ¤ä¥¹¥¯¥ê¥×¥È¤ä ELF ¤Î¥¤¥ó¥¿¥×¥ê¥¿¤Î¹½À®Í×ÁǤ¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ê¤¤¡£
707 .TP
708 .B EPERM
709 .\"O The file system is mounted
710 .\"O .IR nosuid ,
711 .\"O the user is not the superuser,
712 .\"O and the file has the set-user-ID or set-group-ID bit set.
713 ¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¤¬
714 .I nosuid
715 ¤Ç¥Þ¥¦¥ó¥È¤µ¤ì¡¢¥æ¡¼¥¶¤¬¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Ç¤Ê¤¯¡¢
716 ¥Õ¥¡¥¤¥ë¤Ë set-user-ID ¤¢¤ë¤¤¤Ï set-group-ID ¥Ó¥Ã¥È¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¡£
717 .TP
718 .B EPERM
719 .\"O The process is being traced, the user is not the superuser and the
720 .\"O file has the set-user-ID or set-group-ID bit set.
721 ¥×¥í¥»¥¹¤¬¥È¥ì¡¼¥¹¤µ¤ì¡¢¥æ¡¼¥¶¤¬¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Ç¤Ê¤¯¡¢
722 ¥Õ¥¡¥¤¥ë¤Ë set-user-ID ¤¢¤ë¤¤¤Ï set-group-ID ¥Ó¥Ã¥È¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¡£
723 .TP
724 .B ETXTBSY
725 .\"O Executable was open for writing by one or more processes.
726 ¼Â¹Ô¥Õ¥¡¥¤¥ë¤ò½ñ¤­¹þ¤ßÍѤ˥ª¡¼¥×¥ó¤·¤Æ¤¤¤ë¥×¥í¥»¥¹¤¬¤¢¤ë¡£
727 .\"O .SH "CONFORMING TO"
728 .SH ½àµò
729 .\"O SVr4, 4.3BSD, POSIX.1-2001.
730 .\"O POSIX.1-2001 does not document the #!  behavior
731 .\"O but is otherwise compatible.
732 .\"O .\" SVr4 documents additional error
733 .\"O .\" conditions EAGAIN, EINTR, ELIBACC, ENOLINK, EMULTIHOP; POSIX does not
734 .\"O .\" document ETXTBSY, EPERM, EFAULT, ELOOP, EIO, ENFILE, EMFILE, EINVAL,
735 .\"O .\" EISDIR or ELIBBAD error conditions.
736 SVr4, 4.3BSD, POSIX.1-2001.
737 POSIX.1-2001 ¤Ë¤Ï #! Æ°ºî¤Ë¤Ä¤¤¤Æ¤Îµ­½Ò¤Ï¤Ê¤¤¤¬¡¢
738 ¾¤Ï¸ß´¹À­¤¬¤¢¤ë¡£
739 .\" SVr4 ¤Ë¤Ï¾¤Ë EAGAIN, EINTR, ELIBACC, ENOLINK, EMULTIHOP
740 .\" ¤Ë¤Ä¤¤¤Æ¤Îµ­½Ò¤¬¤¢¤ë¡£
741 .\" POSIX ¤Ë¤Ï ETXTBSY, EPERM, EFAULT, ELOOP, EIO, ENFILE, EMFILE,
742 .\" EINVAL, EISDIR, ELIBBAD ¥¨¥é¡¼¾õÂ֤ˤĤ¤¤Æ¤Îµ­½Ò¤Ï¤Ê¤¤¡£
743 .\"O .SH NOTES
744 .SH Ãí°Õ
745 .\"O Set-user-ID and set-group-ID processes can not be
746 .\"O .BR ptrace (2)d.
747 set-user-id ¥×¥í¥»¥¹¤È set-group-ID ¥×¥í¥»¥¹¤Ï
748 .BR ptrace (2)
749 ¤Ç¤­¤Ê¤¤¡£
750
751 .\"O Linux ignores the set-user-ID and set-group-ID bits on scripts.
752 Linux ¤Ï¥¹¥¯¥ê¥×¥È¤Î set-user-ID ¤È set-group-ID ¥Ó¥Ã¥È¤ò̵»ë¤¹¤ë¡£
753
754 .\"O The result of mounting a file system
755 .\"O .I nosuid
756 .\"O varies across Linux kernel versions:
757 .\"O some will refuse execution of set-user-ID and set-group-ID
758 .\"O executables when this would
759 .\"O give the user powers she did not have already (and return
760 .\"O .BR EPERM ),
761 .\"O some will just ignore the set-user-ID and set-group-ID bits and
762 .\"O .BR exec ()
763 .\"O successfully.
764 ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤ò
765 .I nosuid
766 ¤Ç¥Þ¥¦¥ó¥È¤·¤¿¾ì¹ç¤Ë set-user-ID/set-group-ID ¤Î¼Â¹Ô¥Õ¥¡¥¤¥ë¤ò
767 ¤É¤ÎÍͤ˰·¤¦¤«¤Ï¡¢Linux ¥«¡¼¥Í¥ë¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë:
768 ¤¢¤ë¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¡¢¤¹¤Ç¤ËɬÍפʸ¢¸Â¤ò»ý¤Ã¤Æ¤¤¤ë¾ì¹ç¤ò½ü¤¤¤Æ¡¢
769 ¤½¤Î¼Â¹Ô¤òµñÈݤ¹¤ë (¤½¤·¤Æ
770 .B EPERM
771 ¤òÊÖ¤¹)¡£Ê̤Τ¢¤ë¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï
772 set-user-ID/set-group-ID ¥Ó¥Ã¥È¤Î¤ß¤ò̵»ë¤·
773 .BR exec ()
774 ¤ÏÀ®¸ù¤¹¤ë¡£
775
776 .\"O A maximum line length of 127 characters is allowed for the first line in
777 .\"O a #! executable shell script.
778 #! ¼Â¹Ô·Á¼°¤Î¥·¥§¥ë¡¦¥¹¥¯¥ê¥×¥È¤Î 1¹ÔÌܤ˵ö¤µ¤ì¤Æ¤¤¤ëʸ»ú¿ô¤Ï¡¢
779 ºÇÂç 127 Ê¸»ú¤Ç¤¢¤ë¡£
780
781 .\"O The semantics of the
782 .\"O .I optional-arg
783 .\"O argument of an interpreter script vary across implementations.
784 .\"O On Linux, the entire string following the
785 .\"O .I interpreter
786 .\"O name is passed as a single argument to the interpreter,
787 .\"O and this string can include white space.
788 .\"O However, behavior differs on some other systems.
789 .\"O Some systems
790 .\"O .\" e.g., Solaris 8
791 .\"O use the first white space to terminate
792 .\"O .IR optional-arg .
793 .\"O On some systems,
794 .\"O .\" e.g., FreeBSD before 6.0, but not FreeBSD 6.0 onwards
795 .\"O an interpreter script can have multiple arguments,
796 .\"O and white spaces in
797 .\"O .I optional-arg
798 .\"O are used to delimit the arguments.
799 ¥¤¥ó¥¿¥×¥ê¥¿¡¦¥¹¥¯¥ê¥×¥È¤Î
800 .I optional-arg
801 °ú¤­¿ô¤Î²ò¼áÊýË¡¤Ï¼ÂÁõ¤Ë¤è¤ê°Û¤Ê¤ë¡£
802 Linux ¤Ç¤Ï¡¢¥¤¥ó¥¿¥×¥ê¥¿Ì¾
803 .I interpreter
804 ¤Ë³¤¯Ê¸»úÎóÁ´ÂΤ¬¥¤¥ó¥¿¥×¥ê¥¿¤Ë 1¸Ä¤Î°ú¤­¿ô¤È¤·¤ÆÅϤµ¤ì¤ë¡£
805 ¤·¤«¤·¡¢Æ°ºî¤¬°Û¤Ê¤ë¥·¥¹¥Æ¥à¤â¤¢¤ë¡£
806 ¤¢¤ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
807 .\" Î㤨¤Ð¡¢Solaris 8
808 .I optional-arg
809 ¤Î¤¦¤ÁºÇ½é¤Î¥Û¥ï¥¤¥È¡¦¥¹¥Ú¡¼¥¹¤Þ¤Ç¤¬
810 °ú¤­¿ô¤È¤·¤ÆÅϤµ¤ì¤ë¡£
811 ¤Þ¤¿¡¢Ê̤Υ·¥¹¥Æ¥à¤Ç¤Ï
812 .\" Î㤨¤Ð¡¢6.0 ¤è¤êÁ°¤Î FreeBSD (FreeBSD 6.0 °Ê¹ß¤Ï°ã¤¦)
813 ¥¤¥ó¥¿¥×¥ê¥¿¡¦¥¹¥¯¥ê¥×¥È¤ÏÊ£¿ô¤Î°ú¤­¿ô¤ò»ý¤Ä¤³¤È¤¬¤Ç¤­¡¢
814 .I optional-arg
815 Æâ¤Î¥Û¥ï¥¤¥È¡¦¥¹¥Ú¡¼¥¹¤¬°ú¤­¿ô¤Î¶èÀÚ¤ê¤È¤Ê¤ë¡£
816
817 .\"O On Linux,
818 .\"O .I argv
819 .\"O can be specified as NULL,
820 .\"O which has the same effect as specifying this argument
821 .\"O as a pointer to a list containing a single NULL pointer.
822 .\"O .B "Do not take advantage of this misfeature!"
823 .\"O It is nonstandard and nonportable:
824 .\"O on most other Unix systems doing this will result in an error
825 .\"O .RB ( EFAULT ).
826 Linux ¤Ç¤Ï¡¢
827 .I argv
828 ¤Ë NULL ¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¤³¤ì¤Ï¡¢¤³¤Î°ú¤­¿ô¤Ë NULL ¥Ý¥¤¥ó¥¿
829 1¸Ä¤À¤±¤ò´Þ¤à¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ØÄꤷ¤¿¤Î¤ÈƱ¤¸¸ú²Ì¤ò»ý¤Ä¡£
830 .BR ¡Ö¤³¤Î´Ö°ã¤Ã¤¿µ¡Ç½¤òÍøÍѤ·¤Ê¤¤¤³¤È¡× ¡£
831 ¤³¤ì¤ÏÈóɸ½à¤Ç¡¢°Ü¿¢À­¤â¤Ê¤¤¡£
832 ¾¤Î¤Û¤È¤ó¤É¤Î Unix ¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¤³¤ì¤ò¹Ô¤¦¤È¥¨¥é¡¼
833 .RB ( EFAULT )
834 ¤Ë¤Ê¤ë¡£
835 .\" e.g., EFAULT on Solaris 8 and FreeBSD 6.1; but
836 .\" HP-UX 11 is like Linux -- mtk, Apr 2007
837 .\" Bug filed 30 Apr 2007: http://bugzilla.kernel.org/show_bug.cgi?id=8408
838 .\" Bug rejected (because fix would constitute an ABI change).
839 .\"
840
841 .\"O POSIX.1-2001 says that values returned by
842 .\"O .BR sysconf (3)
843 .\"O should be invariant over the lifetime of a process.
844 .\"O However, since Linux 2.6.23, if the
845 .\"O .BR RLIMIT_STACK
846 .\"O resource limit changes, then the value reported by
847 .\"O .B _SC_ARG_MAX
848 .\"O will also change,
849 .\"O to reflect the fact that the limit on space for holding
850 .\"O command-line arguments and environment variables has changed.
851 POSIX.1-2001 ¤Ï¡¢
852 .BR sysconf (3)
853 ¤¬ÊÖ¤¹ÃÍ¤Ï¥×¥í¥»¥¹¤ÎÀ¸Â¸Ãæ¤ÏÊѲ½¤·¤Ê¤¤¤Ù¤­¤À¤È¤·¤Æ¤¤¤ë¡£
854 ¤·¤«¤·¤Ê¤¬¤é¡¢Linux 2.6.23 °Ê¹ß¤Ç¤Ï¡¢¥ê¥½¡¼¥¹¾å¸Â
855 .B RLIMIT_STACK
856 ¤¬ÊѲ½¤·¤¿¾ì¹ç¡¢
857 ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤È´Ä¶­ÊÑ¿ô¤òÊÝ»ý¤¹¤ë¤¿¤á¤Î¶õ´Ö¤ËÂФ¹¤ë¾å¸Â¤¬
858 ÊѲ½¤·¤¿¤³¤È¤òÈ¿±Ç¤·¤Æ¡¢
859 .B _SC_ARG_MAX
860 ¤¬ÊÖ¤¹ÃͤâÊѲ½¤¹¤ë¡£
861 .\"
862 .\"O .\" .SH BUGS
863 .\"O .\" Some Linux versions have failed to check permissions on ELF
864 .\"O .\" interpreters.  This is a security hole, because it allows users to
865 .\"O .\" open any file, such as a rewinding tape device, for reading.  Some
866 .\"O .\" Linux versions have also had other security holes in
867 .\"O .\" .BR execve ()
868 .\"O .\" that could be exploited for denial of service by a suitably crafted
869 .\"O .\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
870 .\" .SH ¥Ð¥°
871 .\" Linux ÈǤÎÃæ¤Ë¤Ï¡¢ELF ¥¤¥ó¥¿¥×¥ê¥¿¤Ë¤ª¤±¤ë
872 .\" ¸¢¸Â¤Î¥Á¥§¥Ã¥¯¤Ë¼ºÇÔ¤¹¤ë¤â¤Î¤¬¤¢¤ë¡£
873 .\" ¤³¤ì¤Ï¥»¥­¥å¥ê¥Æ¥£¥Û¡¼¥ë¤Ç¤¢¤ë¡£
874 .\" ¤Ê¤¼¤Ê¤é¡¢¥æ¡¼¥¶¤ËǤ°Õ¤Î¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤òµö²Ä¤·¤¿¤ê¡¢
875 .\" Æɤ߹þ¤ß¤Î¤¿¤á¤Ë¥Æ¡¼¥×¥Ç¥Ð¥¤¥¹¤ò´¬¤­Ìᤷ¤òµö²Ä¤·¤¿¤ê¤¹¤ë¡£
876 .\" Linux ÈǤÎÃæ¤Ë¤Ï
877 .\" .BR execve ()
878 .\" ¤Ë¾¤Î¥»¥­¥å¥ê¥Æ¥£¥Û¡¼¥ë¤¬
879 .\" Â¸ºß¤¹¤ë¤â¤Î¤â¤¢¤ê¡¢¹ªÌ¯¤ËºÙ¹©¤µ¤ì¤¿ ELF ¥Ð¥¤¥Ê¥ê¤Ë¤è¤Ã¤Æ
880 .\" ¥µ¡¼¥Ó¥¹µñÈÝ (denial of service) ¤ËÍøÍѤµ¤ì¤Æ¤·¤Þ¤¦¡£
881 .\" 2.0.34 ¤Þ¤¿ 2.2.15 ¤Ë¤Ï¡¢ÃΤé¤ì¤Æ¤¤¤ëÌäÂê¤Ï¤Ê¤¤¡£
882 .\"O .SS Historical
883 .SS Îò»Ë
884 .\"O With Unix V6 the argument list of an
885 .\"O .BR exec ()
886 .\"O call was ended by 0,
887 .\"O while the argument list of
888 .\"O .I main
889 .\"O was ended by \-1.
890 .\"O Thus, this argument list was not directly usable in a further
891 .\"O .BR exec ()
892 .\"O call.
893 .\"O Since Unix V7 both are NULL.
894 Unix V6 ¤Ç¤Ï
895 .BR exec ()
896 ¥³¡¼¥ë¤Î°ú¤­¿ô¥ê¥¹¥È¤Ï 0 ¤Ç½ªÃ¼¤µ¤ì¡¢
897 .I main
898 ¤Î°ú¤­¿ô¥ê¥¹¥È¤Ï \-1 ¤Ç½ªÃ¼¤µ¤ì¤Æ¤¤¤¿¡£
899 ¤½¤Î¤¿¤á¡¢
900 .I main
901 ¤Î°ú¤­¿ô¥ê¥¹¥È¤Ï¡¢¤½¤Î¸å¤Î
902 .BR exec ()
903 ¥³¡¼¥ë¤Ë¤ÏľÀÜ»ÈÍѤǤ­¤Ê¤«¤Ã¤¿¡£
904 Unix V7 °Ê¹ß¤Ç¤Ï¡¢¤È¤â¤Ë NULL ¤Ç½ªÃ¼¤µ¤ì¤ë¡£
905 .\"O .SH EXAMPLE
906 .SH Îã
907 .\"O The following program is designed to be execed by the second program below.
908 .\"O It just echoes its command-line one per line.
909 ¤³¤Î¥×¥í¥°¥é¥à¤Ï¡¢°Ê²¼¤ÎÆó¤ÄÌÜ¤Î¥×¥í¥°¥é¥à¤«¤é¼Â¹Ô¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¢¤ë¡£
910 ¥³¥Þ¥ó¥É¥é¥¤¥ó¤ò 1¹Ô¤Ë 1¸Ä¤º¤Äɽ¼¨¤¹¤ë¤À¤±¤Î¥×¥í¥°¥é¥à¤Ç¤¢¤ë¡£
911
912 .in +4n
913 .nf
914 /* myecho.c */
915
916 #include <stdio.h>
917 #include <stdlib.h>
918
919 int
920 main(int argc, char *argv[])
921 {
922     int j;
923
924     for (j = 0; j < argc; j++)
925         printf("argv[%d]: %s\\n", j, argv[j]);
926
927     exit(EXIT_SUCCESS);
928 }
929 .fi
930 .in
931
932 .\"O This program can be used to exec the program named in its command-line
933 .\"O argument:
934 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ç»ØÄꤷ¤¿Ì¾Á°¤Î¥×¥í¥°¥é¥à¤ò
935 ¼Â¹Ô¤¹¤ë¤Î¤Ë»È¤¦¡£
936 .in +4n
937 .nf
938
939 /* execve.c */
940
941 #include <stdio.h>
942 #include <stdlib.h>
943 #include <unistd.h>
944
945 int
946 main(int argc, char *argv[])
947 {
948     char *newargv[] = { NULL, "hello", "world", NULL };
949     char *newenviron[] = { NULL };
950
951     if (argc != 2) {
952         fprintf(stderr, "Usage: %s <file-to-exec>\\n", argv[0]);
953         exit(EXIT_FAILURE);
954     }
955
956     newargv[0] = argv[1];
957
958     execve(argv[1], newargv, newenviron);
959     perror("execve");   /* execve() only returns on error */
960     exit(EXIT_FAILURE);
961 }
962 .fi
963 .in
964
965 .\"O We can use the second program to exec the first as follows:
966 Æó¤ÄÌÜ¤Î¥×¥í¥°¥é¥à¤ò»È¤Ã¤Æ°ì¤ÄÌÜ¤Î¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤¹¤ë¤Ë¤Ï
967 °Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë¡£
968
969 .in +4n
970 .nf
971 .RB "$" " cc myecho.c \-o myecho"
972 .RB "$" " cc execve.c \-o execve"
973 .RB "$" " ./execve ./myecho"
974 argv[0]: ./myecho
975 argv[1]: hello
976 argv[2]: world
977 .fi
978 .in
979
980 .\"O We can also use these programs to demonstrate the use of a script
981 .\"O interpreter.
982 .\"O To do this we create a script whose "interpreter" is our
983 .\"O .I myecho
984 .\"O program:
985 ¤µ¤é¤Ë¡¢¤³¤ì¤é¤Î¥×¥í¥°¥é¥à¤ò»È¤Ã¤Æ¡¢¥¹¥¯¥ê¥×¥È¡¦¥¤¥ó¥¿¥×¥ê¥¿¤ÎÎã¤ò¼¨¤¹¡£
986 ¤³¤Î¤¿¤á¤Ë¡¢¡Ö¥¤¥ó¥¿¥×¥ê¥¿¡×¤È¤·¤ÆÀè¤Û¤ÉºîÀ®¤·¤¿¥×¥í¥°¥é¥à
987 .I myecho
988 ¤ò»È¤¦¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë¡£
989
990 .in +4n
991 .nf
992 .RB "$" " cat > script.sh"
993 .B #! ./myecho script-arg
994 .B ^D
995 .RB "$" " chmod +x script.sh"
996 .fi
997 .in
998
999 .\"O We can then use our program to exec the script:
1000 ºîÀ®¤·¤Æ¤ª¤¤¤¿¥×¥í¥°¥é¥à¤ò»È¤Ã¤Æ¥¹¥¯¥ê¥×¥È¤ò¼Â¹Ô¤¹¤ë¡£
1001
1002 .in +4n
1003 .nf
1004 .RB "$" " ./execve ./script.sh"
1005 argv[0]: ./myecho
1006 argv[1]: script-arg
1007 argv[2]: ./script.sh
1008 argv[3]: hello
1009 argv[4]: world
1010 .fi
1011 .in
1012 .\"O .SH "SEE ALSO"
1013 .SH ´ØÏ¢¹àÌÜ
1014 .BR chmod (2),
1015 .BR fork (2),
1016 .BR ptrace (2),
1017 .BR execl (3),
1018 .BR fexecve (3),
1019 .BR getopt (3),
1020 .BR credentials (7),
1021 .BR environ (7),
1022 .BR path_resolution (7),
1023 .BR ld.so (8)