.\" .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for .\" permission to reproduce portions of its copyrighted documentation. .\" Original documentation from The Open Group can be obtained online at .\" http://www.opengroup.org/bookstore/. .\" .\" The Institute of Electrical and Electronics Engineers and The Open .\" Group, have given us permission to reprint portions of their .\" documentation. .\" .\" In the following statement, the phrase ``this text'' refers to portions .\" of the system documentation. .\" .\" Portions of this text are reprinted and reproduced in electronic form .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, .\" Standard for Information Technology -- Portable Operating System .\" Interface (POSIX), The Open Group Base Specifications Issue 6, .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics .\" Engineers, Inc and The Open Group. In the event of any discrepancy .\" between these versions and the original IEEE and The Open Group .\" Standard, the original IEEE and The Open Group Standard is the referee .\" document. The original Standard can be obtained online at .\" http://www.opengroup.org/unix/online.html. .\" .\" This notice shall appear on any product containing this material. .\" .\" The contents of this file are subject to the terms of the .\" Common Development and Distribution License (the "License"). .\" You may not use this file except in compliance with the License. .\" .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE .\" or http://www.opensolaris.org/os/licensing. .\" See the License for the specific language governing permissions .\" and limitations under the License. .\" .\" When distributing Covered Code, include this CDDL HEADER in each .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. .\" If applicable, add the following below this CDDL HEADER, with the .\" fields enclosed by brackets "[]" replaced with your own identifying .\" information: Portions Copyright [yyyy] [name of copyright owner] .\" .\" .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved. .\" .TH SYSTEM 3C "Dec 14, 2006" .SH NAME system \- issue a shell command .SH SYNOPSIS .LP .nf #include \fBint\fR \fBsystem\fR(\fBconst char *\fR\fIstring\fR); .fi .SH DESCRIPTION .sp .LP The \fBsystem()\fR function causes \fIstring\fR to be given to the shell as input, as if \fIstring\fR 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 \fBwaitpid\fR(3C). .sp .LP If \fIstring\fR is a null pointer, \fBsystem()\fR checks if the shell exists and is executable. If the shell is available, \fBsystem()\fR returns a non-zero value; otherwise, it returns \fB0\fR. .sp .LP The \fBsystem()\fR function sets the \fBSIGINT\fR and \fBSIGQUIT\fR signals to be ignored, and blocks the \fBSIGCHLD\fR signal for the calling thread, while waiting for the command to terminate. The \fBsystem()\fR function does not affect the termination status of any child of the calling processes other than the process it creates. .sp .LP The termination status of the process created by the \fBsystem()\fR function is not affected by the actions of other threads in the calling process (it is invisible to \fBwait\fR(3C)) or by the disposition of the \fBSIGCHLD\fR signal in the calling process, even if it is set to be ignored. No \fBSIGCHLD\fR signal is sent to the process containing the calling thread when the command terminates. .SH RETURN VALUES .sp .LP The \fBsystem()\fR function executes \fBposix_spawn\fR(3C) to create a child process running the shell that in turn executes the commands in \fIstring\fR. If \fBposix_spawn()\fR fails, \fBsystem()\fR returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error; otherwise the exit status of the shell is returned. .SH ERRORS .sp .LP The \fBsystem()\fR function may set \fBerrno\fR values as described by \fBfork\fR(2), in particular: .sp .ne 2 .na \fB\fBEAGAIN\fR\fR .ad .RS 10n A resource control or limit on the total number of processes, tasks or LWPs under execution by a single user, task, project, or zone has been exceeded, or the total amount of system memory available is temporarily insufficient to duplicate this process. .RE .sp .ne 2 .na \fB\fBENOMEM\fR\fR .ad .RS 10n There is not enough swap space. .RE .sp .ne 2 .na \fB\fBEPERM\fR\fR .ad .RS 10n The {\fBPRIV_PROC_FORK\fR} privilege is not asserted in the effective set of the calling process. .RE .SH USAGE .sp .LP The \fBsystem()\fR function manipulates the signal handlers for \fBSIGINT\fR and \fBSIGQUIT\fR. It is therefore not safe to call \fBsystem()\fR in a multithreaded process, since some other thread that manipulates these signal handlers and a thread that concurrently calls \fBsystem()\fR can interfere with each other in a destructive manner. If, however, no such other thread is active, \fBsystem()\fR can safely be called concurrently from multiple threads. See \fBpopen\fR(3C) for an alternative to \fBsystem()\fR that is thread-safe. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Standard _ MT-Level Unsafe .TE .SH SEE ALSO .sp .LP .BR ksh (1), .BR sh (1), .BR popen (3C), .BR posix_spawn (3C), .BR wait (3C), .BR waitpid (3C), .BR attributes (7), .BR standards (7)