SYSTEM(3) BSD Library Functions Manual SYSTEM(3)NAME
system -- pass a command to the shell
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
int
system(const char *command);
DESCRIPTION
The system() function hands the argument command to the command interpreter sh(1). The calling process waits for the shell to finish execut-
ing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD.
If command is a NULL pointer, system() will return non-zero if the command interpreter sh(1) is available, and zero if it is not.
RETURN VALUES
The system() function returns the exit status of the shell as returned by waitpid(2), or -1 if an error occurred when invoking fork(2) or
waitpid(2). A return value of 127 means the execution of the shell failed.
SEE ALSO sh(1), execve(2), fork(2), waitpid(2), popen(3)STANDARDS
The system() function conforms to ISO/IEC 9899:1990 (``ISO C90'') and is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible.
BSD June 4, 1993 BSD
Check Out this Related Man Page
system(3C)system(3C)NAME
system - issue a shell command
SYNOPSIS
#include <stdlib.h>
int system(const char *string);
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(3C).
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. The standard to which the caller conforms determines which shell is used. See standards(5).
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.
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. It is therefore not safe to call system() in a mul-
tithreaded process, since some other thread that manipulates these signal handlers and a thread that concurrently calls system() can inter-
fere with each other in a destructive manner. If, however, no such other thread is active, system() can safely be called concurrently from
multiple threads. See popen(3C) for an alternative to system() that is thread-safe.
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |Unsafe |
+-----------------------------+-----------------------------+
ksh(1), sh(1), exec(2), vfork(2), popen(3C), waitpid(3C), attributes(5), standards(5)
18 Dec 2003 system(3C)
When i try to execute some shell command from my C program using system(), how can I capture the
error that occurs due to the shell command?
The system() command's return values will say if the system() was successfull and not if the shell command is successfull.
When I tested my program, I... (3 Replies)
I wanna use a system function to deal with several data. So I use awk variable FILENAME to transfer the file directory to system command, but it does not work.
I use a shell function "out_function" to deal with data and save the result in another directory with the same file name.
How can I... (2 Replies)
Hello all,
Got a question to ask, in some OS, if a shell command is not an internal command, then it is assumed to be a separate program which is loaded into the memory of the computer and then executed.
In UNIX a different technique is used which does much the same sort of thing. What is the... (2 Replies)
Can anybody help me for writing unix shell scripting on fork();
it will be appreciated, if any body can send me sample, tutorial ...with details. (5 Replies)
Hello,
i am trying to rename a file X to file Y on different location .
lets say the mv command started but for some reason system crashed while it did not finish.
will file Y be created physically with lets say half the records of what was in file X???
thanks in advance. (2 Replies)
What is the difference between the(a) shell and the (a) command-line interpreter?
Here we're talking about the complete dummy question, but could someone point me right.
(yes, have written scripts in for instance bash shell,
and and grepp-ed my way around ....:eek: (4 Replies)
Hey there,
I am trying to pass a command as argument to a function.
The command shows up in $1.
Now I want to execute this command, but if I do a $1
./sample
"bla/blaprintf: warning: ignoring excess arguments, starting with `bla/bla'
The code is :
#!/bin/ksh
fn()
{
$1
}
fn... (3 Replies)
Hi Guys,
Just a question about subprocesses.. Lately one of our servers has started to throw out the following error:
SYSTEM ERROR: Too many subprocesses, cannot fork. Errno=12
We've already increased the threshold twice. Its now up to 8000 and the swap space has also been increased. We... (6 Replies)
The man system says
During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.
What does this mean?
And if i am making a function that does what system does how do i write this signal stuff? (19 Replies)
Hi ,
help me out
Generally If the fork() is executed successfully Unix will create identical copies address spaces and the execution starts from the next statement of the fork()
So, in such case
output of the following prog must be
#include<stdio.h>
{
printf("\nwelcome to");
fork();... (3 Replies)
Hi folks, I am writing a simple program to understand how fork() and waitpid works, but it doesn't seem that is working like I wanted.
if(fork()==0){
//el hijo
pid1=getpid();
printf("\nSoy el hijo %d",pid1);
}else {
//el padre
if (fork()==0) {
//el hijo
pid2=getpid();... (2 Replies)
Hello, I'm currently implementing the && function in a shell using C. For example, if we input cmd1 && cmd2, then cmd2 executes only when cmd1 exits successfully. I'm thinking about:
int main() {
int i;
char **args;
while(1) {
printf("yongfeng's shell:~$ ");
args =... (5 Replies)
I have a running service which runs in background.
It execute shell commands by function system(cmd)
I need to report fail when command execution takes more than 60 seconds.
Parent doesn't need to wait for 60 seconds of time if the cmd execution completed already.
runCommand()
{
pid_t... (3 Replies)