8_16.c-->exec
2015-10-27 10:45
399 查看
只是取到了一个参数呀。
shell下执行which and echo , They will display the results of two parameters.
file /tmp 8_16.c
/tmp: directory
8_16.c: c program text
1 #include "apue.h"
2 #include <sys/wait.h>
3
4 char *env_init[] = {"USER=unknown","PATH = /tmp",NULL };
5 int main()
6 {
7 pid_t pid;
8 if ((pid = fork()) < 0){
9 err_sys("fork error");
10 }
11 else if (pid == 0){
12 if (execle("/home/tingbinz/bin/which","echo","ls",(char *)0,env_init) < 0)
13 err_sys("execle errpr");
14 }
15
16 if (waitpid(pid,NULL,0) < 0)
17 err_sys("waitpid error");
18
19 if ((pid = fork()) < 0)
20 err_sys("fork error");
21 else if (pid == 0){
22 if(execlp("file","/tmp","8_16.c",(char *)0) < 0)
23 err_sys("fork error");
24
25 }
26 return 0;
27
28 }
2.running result:
<bldc:/home/tingbinz/apue.3e/SBSCODE/8>R*_*G:./exec
/usr/bin/ls
<bldc:/home/tingbinz/apue.3e/SBSCODE/8>R*_*G:8_16.c: c program text
shell下执行which and echo , They will display the results of two parameters.
file /tmp 8_16.c
/tmp: directory
8_16.c: c program text
1 #include "apue.h"
2 #include <sys/wait.h>
3
4 char *env_init[] = {"USER=unknown","PATH = /tmp",NULL };
5 int main()
6 {
7 pid_t pid;
8 if ((pid = fork()) < 0){
9 err_sys("fork error");
10 }
11 else if (pid == 0){
12 if (execle("/home/tingbinz/bin/which","echo","ls",(char *)0,env_init) < 0)
13 err_sys("execle errpr");
14 }
15
16 if (waitpid(pid,NULL,0) < 0)
17 err_sys("waitpid error");
18
19 if ((pid = fork()) < 0)
20 err_sys("fork error");
21 else if (pid == 0){
22 if(execlp("file","/tmp","8_16.c",(char *)0) < 0)
23 err_sys("fork error");
24
25 }
26 return 0;
27
28 }
2.running result:
<bldc:/home/tingbinz/apue.3e/SBSCODE/8>R*_*G:./exec
/usr/bin/ls
<bldc:/home/tingbinz/apue.3e/SBSCODE/8>R*_*G:8_16.c: c program text
相关文章推荐
- Java 实现导出excel表
- Android NDK开发(八)——应用监听自身卸载,弹出用户反馈调查
- 在进程中运行新代码 execl、execle、execlp、execv、execve和execvp函数
- 利用文件描述符及exec系统函数实现简单的cp
- exec函数族
- 子进程的环境变量问题
- exec系列函数(execl,execlp,execle,execv,execvp)使用
- (进程的变身)exec函数族
- Qt之无边框自定义最小化、关闭按钮并实现窗口移动
- UIViewUILabel
- easyUI导出excel文件 提供下载功能
- 妙用“Check out”与“Check In”
- window配置redis linux配置redis
- Tips:获取 APP 的 Launch Image
- css中float left与float right的使用说明
- 1、开发环境的搭建
- 基于javascript的分页技术
- Bootstrap 全局css样式布局之 栅格系统
- iOS应用程序的生命周期
- JavaScript 代码性能优化总结