Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

system(3) [osx man page]

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(3)						     Linux Programmer's Manual							 SYSTEM(3)

NAME
system - execute a shell command SYNOPSIS
#include <stdlib.h> int system(const char *string); DESCRIPTION
system() executes a command specified in string by calling /bin/sh -c string, and returns after the command has been completed. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored. RETURN VALUE
The value returned is -1 on error (e.g. fork failed), and the return status of the command otherwise. This latter return status is in the format specified in wait(2). Thus, the exit code of the command will be WEXITSTATUS(status). In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127). If the value of string is NULL, system() returns nonzero if the shell is available, and zero if not. system() does not affect the wait status of any other children. CONFORMING TO
ANSI C, POSIX.2, BSD 4.3 NOTES
As mentioned, system() ignores SIGINT and SIGQUIT. This may make programs that call it from a loop uninterruptable, unless they take care themselves to check the exit status of the child. E.g. while(something) { int ret = system("foo"); if (WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT)) break; } Do not use system() from a program with suid or sgid privileges, because strange values for some environment variables might be used to subvert system integrity. Use the exec(3) family of functions instead, but not execlp(3) or execvp(3). system() will not, in fact, work properly from programs with suid or sgid privileges on systems on which /bin/sh is bash version 2, since bash 2 drops privileges on startup. (Debian uses a modified bash which does not do this when invoked as sh.) The check for the availability of /bin/sh is not actually performed; it is always assumed to be available. ISO C specifies the check, but POSIX.2 specifies that the return shall always be non-zero, since a system without the shell is not conforming, and it is this that is implemented. It is possible for the shell command to return 127, so that code is not a sure indication that the execve() call failed. SEE ALSO
sh(1), signal(2), wait(2), exec(3) 2001-09-23 SYSTEM(3)
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

system()

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