system(S) 6 January 1993 system(S) Name system - issue a shell command Syntax cc . . . -lc #include <stdio.h> #include <stdlib.h> int system (string) char *string; Description The system function causes the string to be given to sh(C) as input, as if the string had been typed as a command at a terminal. The current process waits until the shell has completed. Files /bin/sh Return value If string is not a null pointer, system returns the exit status of the shell in the same format as specified by the waitpid(S) function. The meaning of the return value, if it is not -1, can be decoded via macros like WIFEXITED defined in <sys/wait.h>, as described in waitpid(S). Diagnostics The system function forks to create a child process that in turn executes (using exec(S)) /bin/sh in order to execute string. If the fork fails, system returns -1 and sets errno. If the fork succeeds but exec fails, system returns a value as if sh(C) had terminated using exit(127). The system function fails if: [EAGAIN] The system-imposed limit on the total number of processes under execution, system-wide, or by a single user ID (CHILDMAX), would be exceeded. [ENOMEM] Insufficient storage space is available. See also exec(S), sh(C) Standards conformance system is conformant with: AT&T SVID Issue 2; X/Open Portability Guide, Issue 3, 1989; and ANSI X3.159-1989 Programming Language -- C.