1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
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
28 .TH SYSTEM 3 2010-09-10 "" "Linux Programmer's Manual"
30 system \- execute a shell command
33 .B #include <stdlib.h>
35 .BI "int system(const char *" "command" );
39 executes a command specified in
44 and returns after the command has been completed.
45 During execution of the command,
53 The value returned is \-1 on error (e.g.,
56 and the return status of the command otherwise.
57 This latter return status is in the format
60 Thus, the exit code of the command will be
61 .IR WEXITSTATUS(status) .
64 could not be executed, the exit status will be that of
72 returns nonzero if the shell is available, and zero if not.
75 does not affect the wait status of any other children.
77 C89, C99, POSIX.1-2001.
82 feature test macro is defined
86 then the macros described in
89 etc.) are made available when including
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.
106 int ret = system("foo");
108 if (WIFSIGNALED(ret) &&
109 (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
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.
121 family of functions instead, but not
126 will not, in fact, work properly from programs with set-user-ID or
127 set-group-ID privileges on systems on which
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
133 In versions of glibc before 2.1.3, the check for the availability of
135 was not actually performed if
137 was NULL; instead it was always assumed to be available, and
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
145 (which is not specified by POSIX.1-2001).
147 It is possible for the shell command to return 127, so that code is not
148 a sure indication that the