描述
system()库函数使用fork(2)创建一个子进程,该子进程使用execl(3)执行指定的shell命令,
execl("/bin/sh", “sh”, “-c”, command,...(char *) 0);
头文件
system - execute a shell command
#include
int system(const char *command...);
返回值
如果子进程无法创建,或者其状态不能被检索,则返回值为-1;
如果在子进程中不能执行一个shell,或shell未正常的结束,返回值被写入到status的低8~15比特位中;一般为127值..., 总结一下,system的返回值需要通过以下三个步骤确定
首先判断子进程是否成功, status !...返回值判断 命令是否正确执行
Linux system函数返回值
父进程等待子进程终止 wait, WIFEXITED, WEXITSTATUS