DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

system(S-osr5)


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-osr5) 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-osr5).

Diagnostics

The system function forks to create a child process that in turn executes (using exec(S-osr5)) /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 (CHILD_MAX), would be exceeded.

[ENOMEM]
Insufficient storage space is available.

See also

_exit(S-osr5), exec(S-osr5), sh(C)

Standards conformance

system is conformant with:

X/Open Portability Guide, Issue 3, 1989 ;
and ANSI X3.159-1989 Programming Language -- C .


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005