Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
system(3)
Edit
PageHistory
Diff
Info
LikePages
SYSTEM !!!SYSTEM NAME SYNOPSIS DESCRIPTION RETURN VALUE CONFORMING TO BUGS SEE ALSO ---- !!NAME system - execute a shell command !!SYNOPSIS __#include __ ''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 !!BUGS It is extremely unfortunate that the libc version of __system()__ ignores interrupts. This makes programs that call it from a loop uninterruptable. This means that for such purposes one should not use __system()__ but a private version like (warning: untested code!) int my_system (const char *command) { int pid, status; if (command == 0) return 1; pid = fork(); if (pid == -1) return -1; if (pid == 0) { char *argv[[4]; argv[[0] = 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; check ''errno'' to make sure. !!SEE ALSO sh(1), signal(2), exec(3) ----
5 pages link to
system(3)
:
pclose(3)
Man3s
confstr(3)
popen(3)
BufferOverflow
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.