进程

定义:一个其中运行着一个或者多个线程的地址空间和这些线程所需要的系统资源。

启动新进程:

方式一 system函数。

  #include <stdlib.h>

  int system (const char *string);

  eg:

  #include <stdlib.h>

  #include <stdio.h>

  int main(){

    printf("running ps with system ");

    system("ps ax");

    printf("Done. ");

    exit(0);

  }

  一般来说,使用system函数远非启动其他进程的理想手段,因为它必须用一个shell来启动需要的程序。由于在启动程序之前需要启动一个shell,而且对shenll的安装情况及使用的环境的依赖

  也很大,所以system函数的效率不高。        

方式二 替换进程镜像。

  exec系列函数由一组相关的函数组成,他们在进程的启动方式和程序参数的表达方式上各有不同。exec函数可以把当前进程替换成为一个新进程,新进程由path或file参数决定。你可以使用

  exec函数将程序的执行从一个程序切换到另一个程序。exec函数比system函数更有效,因为在新的程序启动后,原来的程序就不在运行了。  

  函数原型:

  int execl(const char *path,const char *arg0,...,(char *)0);

  int execlp(const char *path,const char *arg0,...,(char *)0);

  

原文地址:https://www.cnblogs.com/airduce/p/9573950.html