Linux 高并发学习笔记 - exec 函数簇重载进程

2.2.4 exec 函数簇重载进程

Linux 高并发学习笔记 - 笔记索引

  • execlexeclpexecleexecvexecvpexecvpe
  • exec函数簇将重载进程,直接覆盖当前进程代码,因此exec函数簇通常需要在fork进程中执行。
  • l:参数使用列表传递,传递一系列参数,以NULL参数(哨兵)结尾。
  • p:在环境变量和当前路径中查找file,其他函数仅在当前路径查找。
  • e:传递envp数组指定路径搜索目录,此时哨兵显得尤为重要。
  • v:参数使用argv数组传递,而不是参数列表。
#include <unistd.h>
int execl(const char *pathname, const char *arg, .../* (char  *) NULL */);
int execlp(const char *file, const char *arg, .../* (char  *) NULL */);
int execle(const char *pathname, const char *arg, .../*, (char *) NULL, char *const envp[] */);
int execv(const char *pathname, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execvpe(const char *file, char *const argv[], char *const envp[]);
// 	execute a file
// 		pathname / file:
// 			the file path to execute
// 		return value:
// 			no return on success, or return -1 for error

// About more
// man 3 exec
  • 注:根据习惯,第一个参数为文件名,即本身。如ps aux参数为psaux
  • 注:如果执行成功没有返回值,因为当前进程代码已覆盖,无法继续执行。
  • 注:system函数实际是对fork函数与exec函数簇的封装,通常使用system函数可以更方便的满足需求。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值