进程替换
来源:互联网 发布:线刷用什么软件 编辑:程序博客网 时间:2024/06/09 19:00
进程替换:exec系列函数
何为进程替换: 一个运行的进程通过某种方式, 用磁盘上存储的程序(可执行文件) 覆
盖原进程的所有的指令和数据。
int execl(char *pathfile, char *argv1, char*argv2, .... , (char*)0);
int execv(char *pathfile, char *argv[]);
execle(const char *path,const char *arg,...,char *const,envp[]);
execve(const char *filename,char *const argv[],char *const envp[]);
execlp
execvp(const char *file,char *const argvp[]);
练习题:
1、exec进程启动输出“。。。。”,sleep 2秒,fork生成子进程, 子进程调用可执行
程序 main, 父进程输出“father start”, 然后sleep 3秒, 输出“father over”;main程序输
出传递给主函数的参数。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <signal.h>
int main(int argc, char *argv[])
{
printf("mykill pid == %d\n", getpid());
if(argc < 2)
{
printf("please input pid\n");
exit(0);
}
{
printf("mykill pid == %d\n", getpid());
if(argc < 2)
{
printf("please input pid\n");
exit(0);
}
//argv[1] = "1234";
int pid = 0;
int pid = 0;
sscanf(argv[1], "%d", &pid);
printf("pid == %d\n", pid);
printf("pid == %d\n", pid);
if(kill(pid, SIGCHLD) == -1)
{
perror(NULL);
exit(0);
}
}
{
perror(NULL);
exit(0);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
void main()
{
printf("exec start\n");
{
printf("exec start\n");
sleep(2);
printf("exec front pid == %d\n", getpid());
execl("./mykill", "./mykill", (char *)0);
printf("exec finish\n");
sleep(2);
printf("exec end\n");
}
}
写时拷贝技术:
fork产生子进程时, 并不会完全复制其父进程。 内核将父进程的所有空间设置为只读,
父子进程共享这些空间, 当父子进程任意一个进程试图修改某个数据时, 内核会将数据所在
的“页” 整体拷贝一份。
阅读全文
0 0
- 进程替换
- bash中的进程替换
- 进程等待&程序替换
- 进程程序替换
- 进程程序替换
- 替换进程execl系列
- 进程的替换
- 进程替换的一点想法
- Process substitution(进程替换)
- 【Linux】进程等待&程序替换
- 【Linux】进程等待&程序替换
- 进程管理之程序替换
- 进程替换(exec函数)
- linux——进程替换
- Linux下的进程3——进程创建,文件替换,进程程序替换
- windowsPE加载器,替换进程内存,
- Bash中的进程替换(process substitution)
- 动态替换目标进程的Java类
- 配置交换机端口具体命令
- 【增强学习】Sarsa
- 基础练习 BASIC-27 2n皇后问题
- JDBC学习之路-对大文本数据的操作
- 解析html
- 进程替换
- 架构师不可不知的十大可扩展架构
- bzoj5043 密码破译
- 百度笔试找出最大信号长度的方法
- 基础练习 BASIC-28 Huffuman树
- 升级nginx 至 1.9.5以上版本 来支持 HTTP 2.0
- MySQL基础操作
- Java 9 中的 9 个新特性
- python:matplotlib及pandas绘图(1)