Sun Microsystems, Inc.
spacerspacer
spacer   www.sun.com docs.sun.com | | |  
spacer
black dot
   
A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z
    
 
Standard C Library Functionssystem(3C)


NAME

 system - issue a shell command

SYNOPSIS

 
#include <stdlib.h>
int system(const char *string);

DESCRIPTION

 

The system() function causes string to be given to the shell as input, as if string had been typed as a command at a terminal. The invoker waits until the shell has completed, then returns the exit status of the shell in the format specified by waitpid(2).

If string is a null pointer, system() checks if the shell exists and is executable. If the shell is available, system() returns a non-zero value; otherwise, it returns 0. If the application is standard-conforming (see standards(5)), system() uses /usr/xpg4/bin/sh (see ksh(1)); otherwise system() uses /usr/bin/sh (see sh(1)).

RETURN VALUES

 

The system() function executes vfork(2) to create a child process that in turn invokes one of the exec family of functions (see exec(2)) on the shell to execute string. If vfork() or the exec function fails, system() returns -1 and sets errno to indicate the error.

ERRORS

 

The system() function fails if:

EAGAIN
The system-imposed limit on the total number of processes under execution by a single user would be exceeded.
EINTR
The system() function was interrupted by a signal.
ENOMEM
The new process requires more memory than is available.

USAGE

 

The system() function manipulates the signal handlers for SIGINT, SIGQUIT, and SIGCHLD. For this reason it is not safe to call system() in a multithreaded process. Concurrent calls to system() will interfere destructively with the disposition of these signals, even if they are not manipulated by other threads in the application. See popen(3C) for a replacement for system() that is thread-safe.

ATTRIBUTES

 

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPEATTRIBUTE VALUE
MT-LevelUnsafe

SEE ALSO

 

ksh(1), sh(1), exec(2), vfork(2), waitpid(2), popen(3C), attributes(5), standards(5)


SunOS 5.9Go To TopLast Changed 20 Dec 2001

 
      
      
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.