.TH system() "" "" "General Function (libc)"
.PC "Pass a command to the shell for execution"
.B "#include <stdlib.h>"
\fBint system(\fIcommandline\^\fB) char *\fIcommandline\fB;\fR
.PP
.B system()
passes \fIcommandline\fR to the shell \fBsh\fR,
which loads it into memory and executes it.
\fBsystem()\fR executes commands exactly as if they had been typed
directly into the shell.
.B system()
may be used by commands such as
.BR ed ,
which can pass commands to the \*(CO shell in addition to
processing normal interactive requests.
.SH Example
This example uses \fBsystem\fR to
list the names of all C source files in the parent directory.
.DM
#include <stdio.h>
#include <stdlib.h>
.DE
.DM
main()
{
	system("cd .. ; ls *.c > mytemp; cat mytemp");
}
.DE
.SH "See Also"
.Xr "exec" exec
.Xr "fork()," fork
.Xr "libc," libc
.Xr "popen()," popen
.Xr "stdlib.h," stdlib.h
.Xr "wait()" wait.s
.br
\*(AS, \(sc7.10.4.5
.SH Diagnostics
\fBsystem()\fR returns the exit status of the child process,
in the format described in
.BR wait() :
exit status in the high byte, signal information in the low byte.
Zero normally means success, whereas nonzero normally means failure.
This, however, depends on the
.IR command .
If the shell is not executable,
.B system()
returns a special code of octal 0177.
