zoukankan      html  css  js  c++  java
  • 迅为i.MX6ULL终结者进程基础 exec函数族

    用fork函数创建子进程后,子进程往往要调用一种exec函数以执行另一个程序,该子进程被新的程序替换,改变地址空间,进程映像和一些属性,但是pid号不变。
    execve():
    #include
    int execve(const char *filename, char *const argv[], char *const envp[]);
    参数含义:
    filename:路径名,表示载入进程空间的新程序路径。
    argv[]:命令行参数,argv[0]为命令名。
    envp[]:新程序的环境变量。
    返回值:成功时不会返回,使用时不用检查返回值,可通过errno检查。
    以下函数都是根据execve实现:
    int execl(const char *path, const char arg, …/ (char *) NULL */);
    int execlp(const char *file, const char arg, …/ (char *) NULL */);
    int execle(const char *path, const char arg, …/, (char *) NULL, char * const envp[] */);
    int execv(const char *path, char *const argv[]);
    int execvp(const char *file, char *const argv[]);
    int execvpe(const char *file, char *const argv[],char *const envp[]);
    实验代码:
    创建子进程,子进程使用execl调用ls查看当前目录下的文件。
    exec.c:
    使用execl调用shell命令查看文件信息。


    执行结果:

    Linux系统基于这些函数实现了“popen”,“system”等函数,这些函数能够直接调用shell等函数。

  • 相关阅读:
    python-Web-django-路由保护
    python-Web-django-图表统计
    python-linux-集群nginx
    python-Web-数据库-oracle
    python-Web-数据库-mysql
    python-爬虫-scrapy
    Educational Codeforces Round 90 (Rated for Div. 2) A~C
    leetcode周赛192
    Codeforces Round #597 (Div. 2) C dp
    Codeforces Round #645 (Div. 2) A~D
  • 原文地址:https://www.cnblogs.com/liyue3/p/14524071.html
Copyright © 2011-2022 走看看