原文链接:linux system函数详解 - 南哥的天下 - 博客园
system()函数的返回值如下: 成功,则返回进程的状态值; 当sh不能执行时,返回127; 失败返回-1;
在前面写exec族函数文章中得代码示例中稍作修改如下:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
// int system(const char *command);
printf("before system\n");
if(system("ps -l") == -1){
printf("system failed!\n");
perror("why");
}
printf("after system\n");
return 0;
}
运行结果: