好像没有是吧,fork exec, 甚至clone都没有这样的功能啊。
windows里,CreateProcess函数执行时,可以传递一个参数 CREATE_SUSPENDED,使进程创建后不执行,然后父进程可以对这个进程做一些设置,比如注入一个dll,然后调用ResumeThread(lpProcessInformation->hThread); 恢复进程的执行。
linux里没有这样的机制吗?
[已解决]linux里有没有使进程创建后马上挂起的函数
- wxf
- 帖子: 53
- 注册时间: 2008-05-28 8:50
[已解决]linux里有没有使进程创建后马上挂起的函数
上次由 wxf 在 2023-08-10 14:36,总共编辑 1 次。
- astolia
- 论坛版主
- 帖子: 6513
- 注册时间: 2008-09-18 13:11
Re: linux里有没有使进程创建后马上挂起的函数
代码: 全选
pid_t pid = fork();
if (pid == 0) {
ptrace(PTRACE_TRACEME, 0, NULL, 0);
execlp("ls", "ls", NULL);
} else {
int status;
waitpid(pid, &status, 0);
if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
printf("child %d suspended, press Enter to continue\n", pid);
getchar();
ptrace(PTRACE_CONT, pid, NULL, 0);
}
}
- wxf
- 帖子: 53
- 注册时间: 2008-05-28 8:50
Re: linux里有没有使进程创建后马上挂起的函数
get到知识了!谢谢大佬astolia 写了: ↑2023-08-10 13:44代码: 全选
pid_t pid = fork(); if (pid == 0) { ptrace(PTRACE_TRACEME, 0, NULL, 0); execlp("ls", "ls", NULL); } else { int status; waitpid(pid, &status, 0); if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) { printf("child %d suspended, press Enter to continue\n", pid); getchar(); ptrace(PTRACE_CONT, pid, NULL, 0); } }