如何掌握了exec族函数,就会发现system比exec简单粗暴多了
system 的原型
int system(const char *command);
具体代码中的用法
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
printf("befor system\n");
if(system("ps") == -1)
{
printf("system failed!\n");
perror("why");
}
printf("after system\n");
return 0;
}

和exec的区别是:system执行完,代码还会回到原点往下执行, exec在代码执行正确是看不到 after xxx 的输出
错误方面也是跟exec是一样,只不过exec是拼接,system是直接覆盖了


system函数的返回值如下:
成功则返回进程的状态值;
当sh不能执行时,返回127;
失败返回-1。