Linux execve函数簇用法
exec函数簇实现的功能都是用一个新程序替换原来的程序,替换的内容包括堆栈段,代码段,进程控制器PCD,但是原进程的PID保持不变
int execl(const char *path, const char *arg, ...);
...表示参数是可变参数列表,例如execl("hello","参数1","参数2","参数3",NULL)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> int main(int arg,char *args[])
{
execl("/bin/ls","/bin/ls","-la",NULL);
/*备注:这里参数写"ls",execl()无法找到ls程序*/
printf("fly with me\n");
return ;
}
int execlp(const char *file, const char *arg, ...);
p表示无需填写路径,只要填写文件名称,因为execlp()函数会在当前环境变量PATH下查找该文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> int main(int arg,char *args[])
{
execlp("ls","ls","-la",NULL);
printf("fly with me\n");
return ;
}
int execle(const char *path, const char *arg,..., char * const envp[]);
参数envp是一个以NULL结尾的字符串数组,代表程序员自定义的环境变量,标准写法是KEY=VALUE
如果envp参数传值NULL,在被替换进程打印的是NULL
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h> int main(int arg,char *args[])
{
printf("old getpid()=%d\n",getpid());
char *envps[]={"aa=11","bb=22",NULL};
execle("./hello","./hello",NULL,envps);
return ;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h> extern char **environ; int main(int arg,char *args[])
{
printf("fly with me;getpid()=%d\n",getpid());
int i=;
for(i=;environ[i]!=NULL;i++)
{
printf("%s\n",environ[i]);
}
return ;
}
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
Linux execve函数簇用法的更多相关文章
- linux中execve函数的用法
在父进程中fork一个子进程,在子进程中调用exec函数启动新的程序.exec函数一共有六个,其中execve为内核级系统调用,其他(execl,execle,execlp,execv,execvp) ...
- linux execl()函数 关于execl()函数族的用法不在赘述,
linux execl()函数 关于execl()函数族的用法不在赘述, linux 网络编程 1---(基本概念) 1.TCP和UDP协议 共同点:同为传输层协议 不同点: TCP:有连接,可靠 U ...
- Linux里AWK中split函数的用法
跟java里的split函数的用法是很相像的,举例如下: The awk function split(s,a,sep) splits a string s into an awk array a u ...
- C语言中system()函数的用法总结(转)
system()函数功能强大,很多人用却对它的原理知之甚少先看linux版system函数的源码: #include <sys/types.h> #include <sys/wait ...
- Linux Clone函数
Linux Clone函数 之前某一次有过一次面试,问了内核中是怎么创建命名空间的? 下面就来扒一扒clone的精髓,以及如何通过它创建命名空间. 目录 Linux Clone函数 使用clone创建 ...
- linux中make的用法
一.linux中make的用法 目的: 基本掌握了make 的用法,能在Linux系统上编程.环境: Linux系统准备: 准备三个文件:file1.c, file ...
- linux select函数详解
linux select函数详解 在Linux中,我们可以使用select函数实现I/O端口的复用,传递给 select函数的参数会告诉内核: •我们所关心的文件描述符 •对每个描述符,我们所关心的状 ...
- (转)linux 中特殊符号用法详解
linux 中特殊符号用法详解 原文:https://www.cnblogs.com/lidabo/p/4323979.html # 井号 (comments)#管理员 $普通用户 脚本中 #!/b ...
- [转帖]Linux date命令的用法(转)
Linux date命令的用法(转) https://www.cnblogs.com/asxe/p/9317811.html 1.命令:date 2.命令功能:date 可以用来显示或设定系统的日期与 ...
随机推荐
- PHP implode() 函数 把数组元素组合为字符串
http://www.w3school.com.cn/php/func_string_implode.asp PHP implode() 函数 PHP String 函数 实例 把数组元素组合为字符串 ...
- SQLServer安装正常服务启动正常却无法连接
最近给服务器安装sql2008R2版本,发现一个抓狂的问题,我自己觉得,用sql多年,从2005版本到2012版本都从安装到使用都很熟练,竟然被2008版本难住了 给服务器正常安装,sql2008r2 ...
- TypeId和IidManager关系
IidInformation结构 数据类型 名字 string name TypeId::hash_t hash uint16_t parent string groupName size_t siz ...
- yii2 GridView 日期格式化并实现日期可搜索 案例
作者:白狼 出处:http://www.manks.top/article/yii2_gridview_dateformat_search 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且 ...
- 数据库 SQL语句小结(更新中)
################ Navicat,单条执行sql ################ Navicat,数据库管理工具, 在查询的页面有好多命令,若单条执行: 1:可选中要执行的一条sql ...
- 在JavaScript和C#中获得referer
1. JavaScript /** * 获取HTTP请求的Referer * @ishost 布尔类型 Referer为空时是否返回Host(网站首页地址) */ function get_http_ ...
- SQLServer中给表增加组合唯一约束
将两个或者多个字段一起约束成一个唯一约束 alter table 表名 add constraint 约束名 unique (列名1,列名2)
- (原创)大数据时代:基于微软案例数据库数据挖掘知识点总结(Microsoft 决策树分析算法)
随着大数据时代的到来,数据挖掘的重要性就变得显而易见,几种作为最低层的简单的数据挖掘算法,现在利用微软数据案例库做一个简要总结. 应用场景介绍 其实数据挖掘应用的场景无处不在,很多的环境都会应用到数据 ...
- 烂泥:学习mysql的binlog配置
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 1.基础知识 日志是把数据库的每一个变化都记载到一个专用的文件里,这种文件就叫做日志文件.mysql默认只开启错误日志,因为过多的日志将会影响系统的处理 ...
- Linux正则表达式grep
正则表达式是一种符号表示法,用于识别文本模式.Linux处理正则表达式的主要程序是grep.grep搜索与正则表达式匹配的行,并将结果输送至标准输出. 1. grep匹配模式 grep按下述方式接受选 ...