OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / 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  2004-12-20 "" "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, then the macros described in
134 .\"O .BR wait (2)
135 .\"O .RB ( WEXITSTATUS (),
136 .\"O etc.) are made available when including
137 .\"O .IR <stdlib.h> .
138 µ¡Ç½¸¡ºº¥Þ¥¯¥í¤Ç¤¢¤ë
139 .B _XOPEN_SOURCE
140 ¤¬ÄêµÁ¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
141 .BR wait (2)
142 ¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë¥Þ¥¯¥í·²
143 .RB ( WEXITSTATUS ()
144 Åù) ¤¬
145 .I <stdlib.h>
146 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤ÈÍøÍѲÄǽ¤Ë¤Ê¤ë¡£
147 .PP
148 .\"O As mentioned,
149 .\"O .BR system ()
150 .\"O ignores
151 .\"O .B SIGINT
152 .\"O and
153 .\"O .BR SIGQUIT .
154 .\"O This may make programs that call it
155 .\"O from a loop uninterruptible, unless they take care themselves
156 .\"O to check the exit status of the child.
157 .\"O E.g.
158 ´û¤Ë½Ò¤Ù¤¿¤è¤¦¤Ë¡¢
159 .BR system ()
160 ¤Ï
161 .B SIGINT
162 ¤È
163 .B SIGQUIT
164 ¤ò̵»ë¤¹¤ë¡£
165 ¤è¤Ã¤Æ¥ë¡¼¥×¤«¤é
166 .BR system ()
167 ¤ò¸Æ¤Ö¥×¥í¥°¥é¥à¤Ï¡¢
168 °Ê²¼¤ÎÎã¤Î¤è¤¦¤Ë»Ò¥×¥í¥»¥¹¤Î½ªÎ»¾õÂÖ¤ò¼«Ê¬¤Ç¥Á¥§¥Ã¥¯¤·¤Æ¤ª¤«¤Ê¤¤¤È¡¢
169 ÃæÃǤǤ­¤Ê¤¯¤Ê¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
170 .br
171 .nf
172
173     while (something) {
174         int ret = system("foo");
175
176         if (WIFSIGNALED(ret) &&
177             (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
178                 break;
179     }
180 .fi
181 .PP
182 .\"O Do not use
183 .\"O .BR system ()
184 .\"O from a program with set-user-ID or set-group-ID privileges,
185 .\"O because strange values for some environment variables
186 .\"O might be used to subvert system integrity.
187 .\"O Use the
188 .\"O .BR exec (3)
189 .\"O family of functions instead, but not
190 .\"O .BR execlp (3)
191 .\"O or
192 .\"O .BR execvp (3).
193 set-user-ID ¤ä set-group-ID ¤ÎÆø¢¤ò¤â¤Ä¥×¥í¥°¥é¥à¤ÎÃæ¤Ç¤Ï
194 .BR system ()
195 ¤ò»È¤Ã¤Æ¤Ï¤¤¤±¤Ê¤¤¡£¤Ê¤¼¤Ê¤é¡¢¤¢¤ë´Ä¶­ÊÑ¿ô¤Î̤ÃΤÎÃͤˤè¤Ã¤Æ
196 ¥·¥¹¥Æ¥à¤Î°ÂÁ´¤¬Â»¤Ê¤ï¤ì¤ë¤«¤é¤Ç¤¢¤ë¡£Âå¤ï¤ê¤Ë
197 .BR exec (3)
198 ´ØÏ¢¤Î´Ø¿ô·²¤ÎÃæ¤Ç
199 .BR execlp (3)
200 ¤È
201 .BR execvp (3)
202 °Ê³°¤Î´Ø¿ô¤ò»ÈÍѤ¹¤Ù¤­¤Ç¤¢¤ë¡£
203 .\"O .BR system ()
204 .\"O will not, in fact, work properly from programs with set-user-ID or
205 .\"O set-group-ID privileges on systems on which
206 .\"O .I /bin/sh
207 .\"O is bash version 2, since bash 2 drops privileges on startup.
208 .\"O (Debian uses a modified bash which does not do this when invoked as
209 .\"O .BR sh .)
210 ¼ÂºÝ¤Î¤È¤³¤í¡¢
211 .BR system ()
212 ¤Ï
213 .I /bin/sh
214 ¤¬ bash ¥Ð¡¼¥¸¥ç¥ó 2 ¤Ç¤¢¤ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
215 set-user-ID ¤ä set-group-ID ¤ÎÆø¢¤ò»ý¤Ä¥×¥í¥°¥é¥à¤«¤é¤ÏÀµ¤·¤¯Æ°ºî¤·¤Ê¤¤¡£
216 ¤Ê¤¼¤Ê¤é¡¢bash ¥Ð¡¼¥¸¥ç¥ó 2 ¤Ï¥¹¥¿¡¼¥È¥¢¥Ã¥×»þ¤ËÆø¢¤òÍî¤È¤¹¤«¤é¤Ç¤¢¤ë¡£
217 (Debian ¤Ç¤Ï¡¢sh ¤È¤·¤Æµ¯Æ°¤µ¤ì¤¿»þ¤Ë¤Ï¤³¤Î¤è¤¦¤ÊÆ°ºî¤ò¹Ô¤Ê¤ï¤Ê¤¤¤è¤¦¤Ë
218 ½¤Àµ¤µ¤ì¤¿ bash ¤òÍѤ¤¤Æ¤¤¤ë)
219 .PP
220 .\"O In versions of glibc before 2.1.3, the check for the availability of
221 .\"O .I /bin/sh
222 .\"O was not actually performed if
223 .\"O .I command
224 .\"O was NULL; instead it was always assumed to be available, and
225 .\"O .BR system ()
226 .\"O always returned 1 in this case.
227 glibc 2.1.3 ¤è¤êÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¡¢
228 .I command
229 ¤¬ NULL ¤Î¾ì¹ç¤Ë
230 .I /bin/sh
231 ¤¬ÍøÍѲÄǽ¤«¤É¤¦¤«¤Î¥Á¥§¥Ã¥¯¤Ï¼ÂºÝ¤Ë¤Ï¹Ô¤ï¤º¡¢
232 ¤¤¤Ä¤Ç¤âÍøÍѲÄǽ¤Ç¤¢¤ë¤È¤ß¤Ê¤·¤Æ¤¤¤¿¡£
233 .BR system ()
234 ¤Ï¤³¤Î¾ì¹ç¤Ë¾ï¤Ë 1 ¤òÊÖ¤·¤Æ¤¤¤¿¡£
235 .\"O Since glibc 2.1.3, this check is performed because, even though
236 .\"O POSIX.1-2001 requires a conforming implementation to provide
237 .\"O a shell, that shell may not be available or executable if
238 .\"O the calling program has previously called
239 .\"O .BR chroot (2)
240 .\"O (which is not specified by POSIX.1-2001).
241 POSIX.1-2001 ¤Ç¤Ï¥·¥§¥ë¤¬Ä󶡤µ¤ì¤Æ¤¤¤ë¤È¤¤¤¦É¸½à¤Ë½àµò¤·¤¿¼ÂÁõ¤ò
242 Í׵ᤷ¤Æ¤¤¤ë¤¬¡¢glibc 2.1.3 °Ê¹ß¤Ç¤Ï¥·¥§¥ë¤Î¥Á¥§¥Ã¥¯¤ò¼Â¹Ô¤·¤Æ¤¤¤ë¡£
243 ¤Ê¤¼¤Ê¤é¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥°¥é¥à¤¬
244 .BR system ()
245 ¤ò¸Æ¤Ó½Ð¤¹¤è¤êÁ°¤Ë (POSIX.1-2001 ¤Ç¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤)
246 .BR chroot (2)
247 ¤ò¸Æ¤Ó½Ð¤·¤Æ¤¤¤¿»þ¤Ë¤Ï¡¢¥·¥§¥ë¤¬ÍøÍѲÄǽ¤Ç¤Ê¤¤¾ì¹ç¤ä¼Â¹Ô²Äǽ¥Õ¥¡¥¤¥ë
248 ¤Ç¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¤«¤é¤Ç¤¢¤ë¡£
249 .PP
250 .\"O It is possible for the shell command to return 127, so that code is not
251 .\"O a sure indication that the
252 .\"O .BR execve (2)
253 .\"O call failed.
254 ¼Â¹Ô¤·¤¿¥·¥§¥ë¥³¥Þ¥ó¥É¤¬ 127
255 .RB ( /bin/sh
256 ¤Î¸Æ¤Ó½Ð¤·¤Ë¼ºÇÔ¤·¤¿»þ¤ËÊÖ¤¹ÃÍ) ¤òÊÖ¤¹¤³¤È¤â¹Í¤¨¤é¤ì¤ë¡£
257 ¤½¤Î¤¿¤á¡¢¥×¥í¥°¥é¥à¤Ï (¥ê¥¿¡¼¥ó¥³¡¼¥É¤ò¸«¤ë¤À¤±¤Ç¤Ï)
258 .BR execve (2)
259 ¤Î¸Æ¤Ó½Ð¤·¤¬¼ºÇÔ¤·¤¿¤³¤È¤ò³Î¼Â¤ËÃΤ뤳¤È¤Ï¤Ç¤­¤Ê¤¤¡£
260 .\"O .SH "SEE ALSO"
261 .SH ´ØÏ¢¹àÌÜ
262 .BR sh (1),
263 .BR signal (2),
264 .BR wait (2),
265 .BR exec (3)