进程 - exec函数族
进程调用exec函数族执行某个程序
进程当前内容被指定的程序替换
实现让父子进程执行不同的程序
父进程创建子进程
子程序调用exec函数族
父进程不受影响
进程 - execl/execlp
#include<unistd.h>
int execl(const char *path,const char *arg,...);
要执行程序的路径
int execlp(const char *file,const char *arg,...);
成功时执行指定的程序,失败时返回EOF
path 执行的程序名称,包含路径
arg...传递给执行的程序的参数列表
file 执行的程序的名称,在PATH中查找
进程创建 - execl(p) - 示例
执行ls命令,显示/etc目录下所有文件的详细信息
if(execl("/bin/ls","ls","-a","-l","/etc",NULL)<0){
perror("execl");
}
if(execlp("ls","ls","-a","-l","/etc",NULL)<0){
perror("execlp");
}
进程 - execv/execvp
#include<unistd.h>
int execv(const char *path,char *const argv[]);
int execvp(const char *file,char *const argv[]);
成功时执行肯定的程序,失败时返回EOF
arg...封装成指针数组的形式
进程创建 - execv(p) - 示例
执行ls命令,显示/etc目录下所有文件的详细信息
char *arg[]={"ls","-a","-l","/etc",NULL};
if(execv("/bin/ls",arg)<0){
perror("execv");
}
char *arg[]={"ls","-a","-l","/etc",NULL};
if(execvp("ls",arg)<0){
perror("execvp");
}
进程 - system
#include<stdlib.h>
int system(const char *command);
成功时返回命令command的返回值,失败时返回EOF
当前进程等待command执行结束后才继续执行
详细解决方案
exec函数与system(linux进程和线程学习笔记)
热度:49 发布时间:2024-02-25 06:06:17.0
相关解决方案
- linux+tomcat部署JSP项目有关问题,找不到jar依赖包
- linux 上log4j使用,日志输出的配置
- linux 上Tomcat不解析.war包
- 使用moto sdk 6.2 for linux 模拟器调试 蓝牙程序时的有关问题
- 文件下传到系统中后,没有执行权限(linux)
- System.arraycopy()的1点疑问
- 为什么虚拟串口安装了不能用 显示“Unable loading system driver ,the application will be eixt.”解决办法
- linux 命令 求解解决方法
- System.out.println(1.001*1000)输出结果为什么是1000.99999999?解决方法
- Runtime.getRuntime().exec("cmd copy G:\\a\\ C:\\goods\\");没有作用解决办法
- Runtime.getRuntime().exec();如何写
- System.out.println(3L == 3f);结果为什么为true解决思路
- system.out.println(-8>>>2),输出1073741822。求解释。多谢
- System.out.println(3/2>一);输出什么
- System.Security 命名空间解决方法
- System:String 转 std上的string
- 一个关于“不能将参数 1 从“char [80]”转换为“System:Object ^”的有关问题
- System:String 转 std下的string解决办法
- 无法在 System.String 和 System.Int64 上执行“=”操作。解决思路
- System:String转换有关问题
- System.ArgumentNullException 以及 Array的CopyTo 有关问题
- System.out.println ( 'A' +20.5 );的运行结果是85.5,该如何解决
- j# 里如何定义和 C#同样功能的 override void DefWndProc(ref System.Windows.Forms.Message m) 多谢,很
- System.out.println ( 'A' +20.5 );的运作结果是85.5
- System.out.println ( 'A' +20.5 );的运作结果是85.5
- 上载个…System.Web.DataVisualizatio有关问题解决了!来的送分
- System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性异常
- 未能加载文件或程序集“System.Web.Mvc, Version=3.0.0.0, .该怎么解决
- 未能加载资料或程序集“System.Web.Mvc, Version=3.0.0.0, .
- “System.Web.UI”中不存在部类或命名空间名称“ScriptManager"