OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man3 / system.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\" License.
23 .\" Modified Sat Jul 24 17:51:15 1993 by Rik Faith (faith@cs.unc.edu)
24 .\" Modified 11 May 1998 by Joseph S. Myers (jsm28@cam.ac.uk)
25 .\" Modified 14 May 2001, 23 Sep 2001 by aeb
26 .\" 2004-12-20, mtk
27 .\"
28 .\" Japanese Version Copyright (c) 1996 Shoichi OZAWA
29 .\"     all right reserved.
30 .\" Translated 1996-09-01, Shoichi OZAWA <ozawa@omika.hitachi.co.jp>
31 .\" Updated 2001-03-19, Kentaro Shirakata <argrath@ub32.org>
32 .\" Updated 2001-10-16, Kentaro Shirakata <argrath@ub32.org>
33 .\" Updated 2005-02-27, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
34 .\"
35 .\"WORD:        feature test macro      µ¡Ç½¸¡ºº¥Þ¥¯¥í
36 .\"
37 .TH SYSTEM 3  2010-09-10 "" "Linux Programmer's Manual"
38 .\"O .SH NAME
39 .SH Ì¾Á°
40 .\"O system \- execute a shell command
41 system \- ¥·¥§¥ë¥³¥Þ¥ó¥É¤Î¼Â¹Ô
42 .\"O .SH SYNOPSIS
43 .SH ½ñ¼°
44 .nf
45 .B #include <stdlib.h>
46 .sp
47 .BI "int system(const char *" "command" );
48 .fi
49 .\"O .SH DESCRIPTION
50 .SH ÀâÌÀ
51 .\"O .BR system ()
52 .\"O executes a command specified in
53 .\"O .I command
54 .\"O by calling
55 .\"O .BR "/bin/sh \-c"
56 .\"O .IR command ,
57 .\"O and returns after the command has been completed.
58 .BR system ()
59 ¤Ï
60 .I command
61 ¤Ç»ØÄꤷ¤¿¥³¥Þ¥ó¥É¤ò
62 .B "/bin/sh \-c"
63 .I command
64 ¤Î·Á¤Ç¼Â¹Ô¤¹¤ë¡£»ØÄꤷ¤¿¥³¥Þ¥ó¥É¤¬½ªÎ»¤¹¤ì¤Ð¤³¤Î´Ø¿ô¤â½ªÎ»¤¹¤ë¡£
65 .\"O During execution of the command,
66 .\"O .B SIGCHLD
67 .\"O will be blocked, and
68 .\"O .B SIGINT
69 .\"O and
70 .\"O .B SIGQUIT
71 .\"O will be ignored.
72 ¥³¥Þ¥ó¥É¼Â¹ÔÃæ¤Ï¡¢
73 .B SIGCHLD
74 ¤Ï¥Ö¥í¥Ã¥¯¤µ¤ì¡¢
75 .B SIGINT
76 ¤È
77 .B SIGQUIT
78 ¤Ï̵»ë¤µ¤ì¤ë¡£
79 .\"O .SH "RETURN VALUE"
80 .SH ÊÖ¤êÃÍ
81 .\"O The value returned is \-1 on error (e.g.
82 .\"O .BR fork (2)
83 .\"O failed),
84 .\"O and the return status of the command otherwise.
85 ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç
86 .RB ( fork (2)
87 ¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤Ê¤É)¡¢\-1 ¤òÊÖ¤¹¡£
88 ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¥³¥Þ¥ó¥É¤Î¥¹¥Æ¡¼¥¿¥¹¤òÊÖ¤¹¡£
89 .\"O This latter return status is in the format
90 .\"O specified in
91 .\"O .BR wait (2).
92 ¸å¼Ô¤Î¾ì¹ç¡¢¥¹¥Æ¡¼¥¿¥¹¤Ï
93 .BR wait (2)
94 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¥Õ¥©¡¼¥Þ¥Ã¥È¤ÇÊ֤äƤ¯¤ë¡£
95 .\"O Thus, the exit code of the command will be
96 .\"O .IR WEXITSTATUS(status) .
97 ½¾¤Ã¤Æ¡¢¥³¥Þ¥ó¥É¤Î½ªÎ»¥³¡¼¥É¤Ï
98 .I WEXITSTATUS(status)
99 ¤ÇÆÀ¤ë¤³¤È¤¬½ÐÍè¤ë¡£
100 .\"O In case
101 .\"O .I "/bin/sh"
102 .\"O could not be executed, the exit status will be that of
103 .\"O a command that does
104 .\"O .IR exit(127) .
105 .I /bin/sh
106 ¤¬¼Â¹Ô½ÐÍè¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
107 ½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤Ï¥³¥Þ¥ó¥É¤¬
108 .I exit(127)
109 ¤ò¼Â¹Ô¤·¤¿¾ì¹ç¤ÈƱ¤¸¤Ë¤Ê¤ë¡£
110 .PP
111 .\"O If the value of
112 .\"O .I command
113 .\"O is NULL,
114 .\"O .BR system ()
115 .\"O returns nonzero if the shell is available, and zero if not.
116 .I command
117 ¤ÎÃͤ¬ NULL ¤Î¤È¤­¤Ï¡¢
118 .BR system ()
119 ¤Ï¥·¥§¥ë¤¬ÍøÍѲÄǽ¤Ê¤é¥¼¥í°Ê³°¤ÎÃͤòÊÖ¤·¡¢ÍøÍÑÉԲĤʤ饼¥í¤òÊÖ¤¹¡£
120 .PP
121 .\"O .BR system ()
122 .\"O does not affect the wait status of any other children.
123 .BR system ()
124 ¤Ï¾¤Î»Ò¥×¥í¥»¥¹¤Î¥¦¥¨¥¤¥È¥¹¥Æ¡¼¥¿¥¹¤Ë¤Ï±Æ¶Á¤òÍ¿¤¨¤Ê¤¤¡£
125 .\"O .SH "CONFORMING TO"
126 .SH ½àµò
127 C89, C99, POSIX.1-2001.
128 .\"O .SH NOTES
129 .SH Ãí°Õ
130 .PP
131 .\"O If the
132 .\"O .B _XOPEN_SOURCE
133 .\"O feature test macro is defined
134 .\"O (before including
135 .\"O .I any
136 .\"O header files),
137 .\"O then the macros described in
138 .\"O .BR wait (2)
139 .\"O .RB ( WEXITSTATUS (),
140 .\"O etc.) are made available when including
141 .\"O .IR <stdlib.h> .
142 (¡Ö¤É¤Î¡×¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤è¤ê¤âÁ°¤Ë)
143 µ¡Ç½¸¡ºº¥Þ¥¯¥í
144 .B _XOPEN_SOURCE
145 ¤¬ÄêµÁ¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
146 .BR wait (2)
147 ¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë¥Þ¥¯¥í·²
148 .RB ( WEXITSTATUS ()
149 Åù) ¤¬
150 .I <stdlib.h>
151 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤ÈÍøÍѲÄǽ¤Ë¤Ê¤ë¡£
152 .PP
153 .\"O As mentioned,
154 .\"O .BR system ()
155 .\"O ignores
156 .\"O .B SIGINT
157 .\"O and
158 .\"O .BR SIGQUIT .
159 .\"O This may make programs that call it
160 .\"O from a loop uninterruptible, unless they take care themselves
161 .\"O to check the exit status of the child.
162 .\"O E.g.
163 ´û¤Ë½Ò¤Ù¤¿¤è¤¦¤Ë¡¢
164 .BR system ()
165 ¤Ï
166 .B SIGINT
167 ¤È
168 .B SIGQUIT
169 ¤ò̵»ë¤¹¤ë¡£
170 ¤è¤Ã¤Æ¥ë¡¼¥×¤«¤é
171 .BR system ()
172 ¤ò¸Æ¤Ö¥×¥í¥°¥é¥à¤Ï¡¢
173 °Ê²¼¤ÎÎã¤Î¤è¤¦¤Ë»Ò¥×¥í¥»¥¹¤Î½ªÎ»¾õÂÖ¤ò¼«Ê¬¤Ç¥Á¥§¥Ã¥¯¤·¤Æ¤ª¤«¤Ê¤¤¤È¡¢
174 ÃæÃǤǤ­¤Ê¤¯¤Ê¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
175 .br
176 .nf
177
178     while (something) {
179         int ret = system("foo");
180
181         if (WIFSIGNALED(ret) &&
182             (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
183                 break;
184     }
185 .fi
186 .PP
187 .\"O Do not use
188 .\"O .BR system ()
189 .\"O from a program with set-user-ID or set-group-ID privileges,
190 .\"O because strange values for some environment variables
191 .\"O might be used to subvert system integrity.
192 .\"O Use the
193 .\"O .BR exec (3)
194 .\"O family of functions instead, but not
195 .\"O .BR execlp (3)
196 .\"O or
197 .\"O .BR execvp (3).
198 set-user-ID ¤ä set-group-ID ¤ÎÆø¢¤ò¤â¤Ä¥×¥í¥°¥é¥à¤ÎÃæ¤Ç¤Ï
199 .BR system ()
200 ¤ò»È¤Ã¤Æ¤Ï¤¤¤±¤Ê¤¤¡£¤Ê¤¼¤Ê¤é¡¢¤¢¤ë´Ä¶­ÊÑ¿ô¤Î̤ÃΤÎÃͤˤè¤Ã¤Æ
201 ¥·¥¹¥Æ¥à¤Î°ÂÁ´¤¬Â»¤Ê¤ï¤ì¤ë¤«¤é¤Ç¤¢¤ë¡£Âå¤ï¤ê¤Ë
202 .BR exec (3)
203 ´ØÏ¢¤Î´Ø¿ô·²¤ÎÃæ¤Ç
204 .BR execlp (3)
205 ¤È
206 .BR execvp (3)
207 °Ê³°¤Î´Ø¿ô¤ò»ÈÍѤ¹¤Ù¤­¤Ç¤¢¤ë¡£
208 .\"O .BR system ()
209 .\"O will not, in fact, work properly from programs with set-user-ID or
210 .\"O set-group-ID privileges on systems on which
211 .\"O .I /bin/sh
212 .\"O is bash version 2, since bash 2 drops privileges on startup.
213 .\"O (Debian uses a modified bash which does not do this when invoked as
214 .\"O .BR sh .)
215 ¼ÂºÝ¤Î¤È¤³¤í¡¢
216 .BR system ()
217 ¤Ï
218 .I /bin/sh
219 ¤¬ bash ¥Ð¡¼¥¸¥ç¥ó 2 ¤Ç¤¢¤ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
220 set-user-ID ¤ä set-group-ID ¤ÎÆø¢¤ò»ý¤Ä¥×¥í¥°¥é¥à¤«¤é¤ÏÀµ¤·¤¯Æ°ºî¤·¤Ê¤¤¡£
221 ¤Ê¤¼¤Ê¤é¡¢bash ¥Ð¡¼¥¸¥ç¥ó 2 ¤Ï¥¹¥¿¡¼¥È¥¢¥Ã¥×»þ¤ËÆø¢¤òÍî¤È¤¹¤«¤é¤Ç¤¢¤ë¡£
222 (Debian ¤Ç¤Ï¡¢sh ¤È¤·¤Æµ¯Æ°¤µ¤ì¤¿»þ¤Ë¤Ï¤³¤Î¤è¤¦¤ÊÆ°ºî¤ò¹Ô¤Ê¤ï¤Ê¤¤¤è¤¦¤Ë
223 ½¤Àµ¤µ¤ì¤¿ bash ¤òÍѤ¤¤Æ¤¤¤ë)
224 .PP
225 .\"O In versions of glibc before 2.1.3, the check for the availability of
226 .\"O .I /bin/sh
227 .\"O was not actually performed if
228 .\"O .I command
229 .\"O was NULL; instead it was always assumed to be available, and
230 .\"O .BR system ()
231 .\"O always returned 1 in this case.
232 glibc 2.1.3 ¤è¤êÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¡¢
233 .I command
234 ¤¬ NULL ¤Î¾ì¹ç¤Ë
235 .I /bin/sh
236 ¤¬ÍøÍѲÄǽ¤«¤É¤¦¤«¤Î¥Á¥§¥Ã¥¯¤Ï¼ÂºÝ¤Ë¤Ï¹Ô¤ï¤º¡¢
237 ¤¤¤Ä¤Ç¤âÍøÍѲÄǽ¤Ç¤¢¤ë¤È¤ß¤Ê¤·¤Æ¤¤¤¿¡£
238 .BR system ()
239 ¤Ï¤³¤Î¾ì¹ç¤Ë¾ï¤Ë 1 ¤òÊÖ¤·¤Æ¤¤¤¿¡£
240 .\"O Since glibc 2.1.3, this check is performed because, even though
241 .\"O POSIX.1-2001 requires a conforming implementation to provide
242 .\"O a shell, that shell may not be available or executable if
243 .\"O the calling program has previously called
244 .\"O .BR chroot (2)
245 .\"O (which is not specified by POSIX.1-2001).
246 POSIX.1-2001 ¤Ç¤Ï¥·¥§¥ë¤¬Ä󶡤µ¤ì¤Æ¤¤¤ë¤È¤¤¤¦É¸½à¤Ë½àµò¤·¤¿¼ÂÁõ¤ò
247 Í׵ᤷ¤Æ¤¤¤ë¤¬¡¢glibc 2.1.3 °Ê¹ß¤Ç¤Ï¥·¥§¥ë¤Î¥Á¥§¥Ã¥¯¤ò¼Â¹Ô¤·¤Æ¤¤¤ë¡£
248 ¤Ê¤¼¤Ê¤é¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥°¥é¥à¤¬
249 .BR system ()
250 ¤ò¸Æ¤Ó½Ð¤¹¤è¤êÁ°¤Ë (POSIX.1-2001 ¤Ç¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤)
251 .BR chroot (2)
252 ¤ò¸Æ¤Ó½Ð¤·¤Æ¤¤¤¿»þ¤Ë¤Ï¡¢¥·¥§¥ë¤¬ÍøÍѲÄǽ¤Ç¤Ê¤¤¾ì¹ç¤ä¼Â¹Ô²Äǽ¥Õ¥¡¥¤¥ë
253 ¤Ç¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¤«¤é¤Ç¤¢¤ë¡£
254 .PP
255 .\"O It is possible for the shell command to return 127, so that code is not
256 .\"O a sure indication that the
257 .\"O .BR execve (2)
258 .\"O call failed.
259 ¼Â¹Ô¤·¤¿¥·¥§¥ë¥³¥Þ¥ó¥É¤¬ 127
260 .RB ( /bin/sh
261 ¤Î¸Æ¤Ó½Ð¤·¤Ë¼ºÇÔ¤·¤¿»þ¤ËÊÖ¤¹ÃÍ) ¤òÊÖ¤¹¤³¤È¤â¹Í¤¨¤é¤ì¤ë¡£
262 ¤½¤Î¤¿¤á¡¢¥×¥í¥°¥é¥à¤Ï (¥ê¥¿¡¼¥ó¥³¡¼¥É¤ò¸«¤ë¤À¤±¤Ç¤Ï)
263 .BR execve (2)
264 ¤Î¸Æ¤Ó½Ð¤·¤¬¼ºÇÔ¤·¤¿¤³¤È¤ò³Î¼Â¤ËÃΤ뤳¤È¤Ï¤Ç¤­¤Ê¤¤¡£
265 .\"O .SH "SEE ALSO"
266 .SH ´ØÏ¢¹àÌÜ
267 .BR sh (1),
268 .BR signal (2),
269 .BR wait (2),
270 .BR exec (3)