Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

system(3) [mojave man page]

SYSTEM(3)						   BSD Library Functions Manual 						 SYSTEM(3)

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)

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)
Man Page

15 More Discussions You Might Find Interesting

1. Programming

get system() answer ?

Hi , how can i get the system reply from a system() command ? is it possible to evaluate the return of a system command ? (4 Replies)
Discussion started by: Sven28
4 Replies

2. Programming


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)
Discussion started by: Deepa
3 Replies

3. Shell Programming and Scripting

can I pass awk variable to system command?

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)
Discussion started by: zhynxn
2 Replies

4. UNIX for Dummies Questions & Answers

How does UNIX....?

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)
Discussion started by: ianlow
2 Replies

5. Shell Programming and Scripting

need help to understand and write script in fork

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)
Discussion started by: manas_ranjan
5 Replies

6. UNIX for Dummies Questions & Answers

return ${1-0}

Hi, What does the above command means? this is used in the following function function _set_return_code { return ${1-0} } (3 Replies)
Discussion started by: neeto
3 Replies

7. UNIX for Dummies Questions & Answers

mv command question

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)
Discussion started by: mjdbouk
2 Replies

8. UNIX for Dummies Questions & Answers

Shell and commandline interpreter-definitions

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)
Discussion started by: amkgw
4 Replies

9. Shell Programming and Scripting

Executing commands through shell variable

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)
Discussion started by: shriyer
3 Replies

10. AIX

Subprocess errors

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)
Discussion started by: Jazmania
6 Replies

11. Programming

Question about system command in C

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)
Discussion started by: omega666
19 Replies

12. Shell Programming and Scripting

help with fork() command???

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)
Discussion started by: vijay496
3 Replies

13. Programming

[C]Fork and waitpid

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)
Discussion started by: lamachejo
2 Replies

14. UNIX for Dummies Questions & Answers

Implement the '&&' function in a shell

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)
Discussion started by: Yongfeng
5 Replies

15. UNIX for Advanced & Expert Users

Command timed out implementation

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)
Discussion started by: techmonk
3 Replies