OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / 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 .TH SYSTEM 3  2010-09-10 "" "Linux Programmer's Manual"
29 .SH NAME
30 system \- execute a shell command
31 .SH SYNOPSIS
32 .nf
33 .B #include <stdlib.h>
34 .sp
35 .BI "int system(const char *" "command" );
36 .fi
37 .SH DESCRIPTION
38 .BR system ()
39 executes a command specified in
40 .I command
41 by calling
42 .BR "/bin/sh \-c"
43 .IR command ,
44 and returns after the command has been completed.
45 During execution of the command,
46 .B SIGCHLD
47 will be blocked, and
48 .B SIGINT
49 and
50 .B SIGQUIT
51 will be ignored.
52 .SH "RETURN VALUE"
53 The value returned is \-1 on error (e.g.
54 .BR fork (2)
55 failed),
56 and the return status of the command otherwise.
57 This latter return status is in the format
58 specified in
59 .BR wait (2).
60 Thus, the exit code of the command will be
61 .IR WEXITSTATUS(status) .
62 In case
63 .I "/bin/sh"
64 could not be executed, the exit status will be that of
65 a command that does
66 .IR exit(127) .
67 .PP
68 If the value of
69 .I command
70 is NULL,
71 .BR system ()
72 returns nonzero if the shell is available, and zero if not.
73 .PP
74 .BR system ()
75 does not affect the wait status of any other children.
76 .SH "CONFORMING TO"
77 C89, C99, POSIX.1-2001.
78 .SH NOTES
79 .PP
80 If the
81 .B _XOPEN_SOURCE
82 feature test macro is defined
83 (before including
84 .I any
85 header files),
86 then the macros described in
87 .BR wait (2)
88 .RB ( WEXITSTATUS (),
89 etc.) are made available when including
90 .IR <stdlib.h> .
91 .PP
92 As mentioned,
93 .BR system ()
94 ignores
95 .B SIGINT
96 and
97 .BR SIGQUIT .
98 This may make programs that call it
99 from a loop uninterruptible, unless they take care themselves
100 to check the exit status of the child.
101 E.g.
102 .br
103 .nf
104
105     while (something) {
106         int ret = system("foo");
107
108         if (WIFSIGNALED(ret) &&
109             (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
110                 break;
111     }
112 .fi
113 .PP
114 Do not use
115 .BR system ()
116 from a program with set-user-ID or set-group-ID privileges,
117 because strange values for some environment variables
118 might be used to subvert system integrity.
119 Use the
120 .BR exec (3)
121 family of functions instead, but not
122 .BR execlp (3)
123 or
124 .BR execvp (3).
125 .BR system ()
126 will not, in fact, work properly from programs with set-user-ID or
127 set-group-ID privileges on systems on which
128 .I /bin/sh
129 is bash version 2, since bash 2 drops privileges on startup.
130 (Debian uses a modified bash which does not do this when invoked as
131 .BR sh .)
132 .PP
133 In versions of glibc before 2.1.3, the check for the availability of
134 .I /bin/sh
135 was not actually performed if
136 .I command
137 was NULL; instead it was always assumed to be available, and
138 .BR system ()
139 always returned 1 in this case.
140 Since glibc 2.1.3, this check is performed because, even though
141 POSIX.1-2001 requires a conforming implementation to provide
142 a shell, that shell may not be available or executable if
143 the calling program has previously called
144 .BR chroot (2)
145 (which is not specified by POSIX.1-2001).
146 .PP
147 It is possible for the shell command to return 127, so that code is not
148 a sure indication that the
149 .BR execve (2)
150 call failed.
151 .SH "SEE ALSO"
152 .BR sh (1),
153 .BR signal (2),
154 .BR wait (2),
155 .BR exec (3)