Appearance
c
#include <stdlib.h>
int system(const char *command);
DESCRIPTION
The system() library function uses fork(2) to create a child process that executes the shell command specified in command using execl(3) as follows:
execl("/bin/sh", "sh", "-c", command, (char *) NULL);相当于 fork() 和 exec() 的简单封装,但它实际上是用/bin/sh来实现的,所以依赖 shell 的会出问题。
用例:
c
system("date +%s > /tmp/out");