文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>linux C中调用shell命令

linux C中调用shell命令

时间:2010-08-20  来源:chinawanglun

linux C中为我们提供了调用shell命令的函数--system
system函数调用/bin/sh  执行特定的shell命令,阻塞当前的进程知道shell命令执行完毕。 #include <stdlib.h> int system(const char *command);
执行system实际上是调用了fork函数(产生新进程)、exec函数(在新进程中执行新任务)、waitpid函数(等待新进程结束)。
system函数举例


#include <stdio.h>
#include <stdlib.h>

int main(int argc,char **argv)
{
    int ret;
    
    printf("当前进程的进程号为%d\n",getpid());
    ret = system("lfs -l");  //调用shell命令 ls -l
    printf("ret = %d\n",ret);
    return 0;
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载