system(3) Library Functions Manual system(3) system - (shell) LIBRARY Standard C library (libc, -lc) #include int system(const char *command); The system() library function behaves as if it used fork(2) to create a child process that executed the shell command specified in command using execl(3) as follows: execl("/bin/sh", "sh", "-c", command, (char *) NULL); system() . SIGCHLD , SIGINT SIGQUIT , system() ( -, command). command NULL, system() , . system() : o command NULL, , , 0, . o - , -1, errno . o -, - _exit(2) 127. o , -, command ( -- ). -- << >>, waitpid(2) (. ., WIFEXITED(), WEXITSTATUS() . .). system() . system() fork(2). attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |system() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ C11, POSIX.1-2008. POSIX.1-2001, C89. system() : fork(2), execl(3) waitpid(2), ; - command. system() : , . _XOPEN_SOURCE ( ), , waitpid(2) (WEXITSTATUS() . .). , system() SIGINT SIGQUIT. , , . : while (something) { int ret = system("foo"); if (WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT)) break; } POSIX.1 , , pthread_atfork(3), system(). glibc . Before glibc 2.1.3, the check for the availability of /bin/sh was not actually performed if command was NULL; instead it was always assumed to be available, and system() always returned 1 in this case. Since glibc 2.1.3, this check is performed because, even though POSIX.1-2001 requires a conforming implementation to provide a shell, that shell may not be available or executable if the calling program has previously called chroot(2) (which is not specified by POSIX.1-2001). , 127, system(); , -. system() ( set-user-ID set-group-ID, ), . , PATH , . exec(3), execlp(3) execvp(3) ( PATH ). system(), , set-user-ID set-group-ID , /bin/sh bash 2: bash 2 ( Debian , dash(1), , sh). , , , . system() . If the command name starts with a hyphen, sh(1) interprets the command name as an option, and the behavior is undefined. (See the -c option to sh(1).) To work around this problem, prepend the command with a space as in the following call: system(" -unfortunate-command-name"); sh(1), execve(2), fork(2), sigaction(2), sigprocmask(2), wait(2), exec(3), signal(7) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , <>. Linux man-pages 6.8 2 2024 . system(3)