1SYSTEM(3)                  Linux Programmer's Manual                 SYSTEM(3)
2
3
4

NAME

6       system - execute a shell command
7

SYNOPSIS

9       #include <stdlib.h>
10
11       int system(const char *command);
12

DESCRIPTION

14       system()  executes a command specified in command by calling /bin/sh -c
15       command, and returns after the command has been completed.  During exe‐
16       cution  of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT
17       will be ignored.
18

RETURN VALUE

20       The value returned is -1 on  error  (e.g.,  fork(2)  failed),  and  the
21       return  status  of the command otherwise.  This latter return status is
22       in the format specified in wait(2).  Thus, the exit code of the command
23       will  be  WEXITSTATUS(status).   In case /bin/sh could not be executed,
24       the exit status will be that of a command that does exit(127).
25
26       If the value of command is NULL, system() returns nonzero if the  shell
27       is available, and zero if not.
28
29       system() does not affect the wait status of any other children.
30

CONFORMING TO

32       C89, C99, POSIX.1-2001.
33

NOTES

35       If  the  _XOPEN_SOURCE  feature test macro is defined (before including
36       any header files), then the macros described in wait(2) (WEXITSTATUS(),
37       etc.) are made available when including <stdlib.h>.
38
39       As  mentioned, system() ignores SIGINT and SIGQUIT.  This may make pro‐
40       grams that call it from a loop uninterruptible, unless they  take  care
41       themselves to check the exit status of the child.  E.g.
42
43           while (something) {
44               int ret = system("foo");
45
46               if (WIFSIGNALED(ret) &&
47                   (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
48                       break;
49           }
50
51       Do  not  use  system()  from a program with set-user-ID or set-group-ID
52       privileges, because strange values for some environment variables might
53       be  used  to subvert system integrity.  Use the exec(3) family of func‐
54       tions instead, but not execlp(3) or execvp(3).  system() will  not,  in
55       fact,  work  properly  from  programs  with set-user-ID or set-group-ID
56       privileges on systems on which /bin/sh is bash version 2, since bash  2
57       drops  privileges  on startup.  (Debian uses a modified bash which does
58       not do this when invoked as sh.)
59
60       In versions of glibc before 2.1.3, the check for  the  availability  of
61       /bin/sh  was not actually performed if command was NULL; instead it was
62       always assumed to be available, and system() always returned 1 in  this
63       case.   Since glibc 2.1.3, this check is performed because, even though
64       POSIX.1-2001 requires a conforming implementation to provide  a  shell,
65       that  shell  may  not be available or executable if the calling program
66       has  previously  called  chroot(2)   (which   is   not   specified   by
67       POSIX.1-2001).
68
69       It is possible for the shell command to return 127, so that code is not
70       a sure indication that the execve(2) call failed.
71

SEE ALSO

73       sh(1), signal(2), wait(2), exec(3)
74

COLOPHON

76       This page is part of release 3.53 of the Linux  man-pages  project.   A
77       description  of  the project, and information about reporting bugs, can
78       be found at http://www.kernel.org/doc/man-pages/.
79
80
81
82                                  2010-09-10                         SYSTEM(3)
Impressum