execv使用
来源:互联网 发布:网络卖淫产业链 编辑:程序博客网 时间:2024/06/03 16:03
转自http://blog.csdn.net/west_609/article/details/5941968
- 函数原型
int execv(const char *progname, char *const argv[]); //#include <unistd.h>
2. 用法介绍
execv会停止执行当前的进程,并且以progname应用进程替换被停止执行的进程,进程ID没有改变。
progname: 被执行的应用程序。
argv: 传递给应用程序的参数列表, 注意,这个数组的第一个参数应该是应用程序名字本身,并且最后一个参数应该为NULL,不参将多个参数合并为一个参数放入数组。
3. 返回值
如果应用程序正常执行完毕,那么execv是永远不会返回的;当execv在调用进程中返回时,那么这个应用程序应该出错了(可能是程序本身没找到,权限不够...), 此时它的返回值应该是-1,具体的错误代码可以通过全局变量errno查看,还可以通过stderr得到具体的错误描述字符串:
4. 示例
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <errno.h>
- main(void)
- {
- pid_t pid = fork();
- if( pid == 0 ) // this is the child process
- {
- execv("/bin/ls", NULL);
- // the program should not reach here, or it means error occurs during execute the ls command.
- printf("command ls is not found, error code: %d(%s)", errno, strerror(errno);
- }
- }
int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const char *arg,
..., char * const envp[]);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
- execv使用
- execv使用
- execv使用
- execv使用
- execv使用
- execv函数使用
- execv
- system()与execv()函数使用详解
- exec系列函数(execl,execlp,execle,execv,execvp)使用
- exec系列函数(execl,execlp,execle,execv,execvp)使用
- linux execv
- execv()函数
- execv注意事项
- linux进程编程-替换进程映-exec系列函数(execl,execlp,execle,execv,execvp)使用
- linux系统编程之进程(五):exec系列函数(execl,execlp,execle,execv,execvp)使用
- linux系统编程:exec系列函数(execl,execlp,execle,execv,execvp)使用
- linux进程编程-替换进程映-exec系列函数(execl,execlp,execle,execv,execvp)使用
- Unix学习笔记-----编程练习实例------使用vfork&&execv()在程序中加载可执行程序
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDOJ 5038 Grade
- 唯品会2015校园招聘技术岗附加题解答
- Java垃圾收集器与内存分配策略
- Codeforces Round #268 (Div. 2)
- execv使用
- Java之父 James Gosling 发表博文 《Too Soon》纪念乔布斯。
- oracle ebs hrms 接口程序
- CoreOS宣布收购Quay.io并启动了CoreOS企业Registry
- 功能键与键盘自定义优先级冲突
- Activity学习(二):Activity的启动模式(转载)
- 第一章 绪论
- android之ScrollView里嵌套ListView
- codeforces 468A 24 Game 构造