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 可以用来显示或设定系统的日期与 ...
随机推荐
- cocoapods遇到的问题 (pod: command not found的问题)
在使用CocoaPod为项目添加第三方类库时,出现了-bash: pod: command not found的问题: 在网上看到了一位哥的方法:确实有效:
- IOS开发之小实例--使用UIImagePickerController创建一个简单的相机应用程序
前言:本篇博文是本人阅读国外的IOS Programming Tutorial的一篇入门文章的学习过程总结,难度不大,因为是入门.主要是入门UIImagePickerController这个控制器,那 ...
- c#.net 使用NPOI导入导出标准Excel (asp.net winform csharp)
尝试过很多Excel导入导出方法,都不太理想,无意中逛到oschina时,发现了NPOI,无需Office COM组件且不依赖Office,顿时惊为天人,怀着无比激动的心情写下此文. 曾使用过的方法 ...
- ORACLE与mysql中查询第n条到第m条的数据记录的方法
ORACLE: SELECT * FROM ( SELECT 表名.*, ROWNUM AS CON FROM 表名 WHERE ROWNUM ...
- [gist]在浏览器里免查看源代码格式化var_dump输出
Gist Link /** * 格式化var_dump输出... * 我勒个去..早怎么没想到..就加了个pre啊,, */ function var_dump_html($var){ echo &q ...
- 磁带机Media is unrecognized
早晨检查磁带备份作业时,发现有个驱动的作业一直处于"Queue"状态,检查发现驱动有磁带,在Alert里面发现出现下面"Media is unrecognized&quo ...
- Spring CharacterEncodingFilter
<!-- 配置请求过滤器,编码格式设为UTF-8,避免中文乱码--> <filter> <filter-name>springUtf8Encoding</fi ...
- 利用PHPMailer 来完成PHP的邮件发送 #转载自:大菜鸟在云端#
利用PHPMailer 来完成PHP的邮件发送 1.首先是下载PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/ 2.解 ...
- scalac error: bad option: '-make:transitive' on mvn package via command line
1 问题描述: ubuntu环境下用eclipse+maven开发Scala的时候出现错误:scalac error: bad option: '-make:transitive' on mvn pa ...
- 九、Android学习第八天——广播机制与WIFI网络操作(转)
(转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 九.Android学习第八天——广播机制与WIFI网络操作 今天熟悉了An ...