1system(3C) Standard C Library Functions system(3C)
2
3
4
6 system - issue a shell command
7
9 #include <stdlib.h>
10
11 int system(const char *string);
12
13
15 The system() function causes string to be given to the shell as input,
16 as if string had been typed as a command at a terminal. The invoker
17 waits until the shell has completed, then returns the exit status of
18 the shell in the format specified by waitpid(3C).
19
20
21 If string is a null pointer, system() checks if the shell exists and is
22 executable. If the shell is available, system() returns a non-zero
23 value; otherwise, it returns 0. The standard to which the caller con‐
24 forms determines which shell is used. See standards(5).
25
26
27 The system() function sets the SIGINT and SIGQUIT signals to be
28 ignored, and blocks the SIGCHLD signal for the calling thread, while
29 waiting for the command to terminate. The system() function does not
30 affect the termination status of any child of the calling processes
31 other than the process it creates.
32
33
34 The termination status of the process created by the system() function
35 is not affected by the actions of other threads in the calling process
36 (it is invisible to wait(3C)) or by the disposition of the SIGCHLD sig‐
37 nal in the calling process, even if it is set to be ignored. No SIGCHLD
38 signal is sent to the process containing the calling thread when the
39 command terminates.
40
42 The system() function executes posix_spawn(3C) to create a child
43 process running the shell that in turn executes the commands in string.
44 If posix_spawn() fails, system() returns −1 and sets errno to indicate
45 the error; otherwise the exit status of the shell is returned.
46
48 The system() function may set errno values as described by fork(2), in
49 particular:
50
51 EAGAIN A resource control or limit on the total number of pro‐
52 cesses, tasks or LWPs under execution by a single user,
53 task, project, or zone has been exceeded, or the total
54 amount of system memory available is temporarily insuffi‐
55 cient to duplicate this process.
56
57
58 ENOMEM There is not enough swap space.
59
60
61 EPERM The {PRIV_PROC_FORK} privilege is not asserted in the
62 effective set of the calling process.
63
64
66 The system() function manipulates the signal handlers for SIGINT and
67 SIGQUIT. It is therefore not safe to call system() in a multithreaded
68 process, since some other thread that manipulates these signal handlers
69 and a thread that concurrently calls system() can interfere with each
70 other in a destructive manner. If, however, no such other thread is
71 active, system() can safely be called concurrently from multiple
72 threads. See popen(3C) for an alternative to system() that is thread-
73 safe.
74
76 See attributes(5) for descriptions of the following attributes:
77
78
79
80
81 ┌─────────────────────────────┬─────────────────────────────┐
82 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
83 ├─────────────────────────────┼─────────────────────────────┤
84 │Interface Stability │Standard │
85 ├─────────────────────────────┼─────────────────────────────┤
86 │MT-Level │Unsafe │
87 └─────────────────────────────┴─────────────────────────────┘
88
90 ksh(1), sh(1), popen(3C), posix_spawn(3C), wait(3C), waitpid(3C),
91 attributes(5), standards(5)
92
93
94
95SunOS 5.11 14 Dec 2006 system(3C)