23,116
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <sys/syscall.h>
#include <time.h>
#include <string.h>
int main()
{
pid_t pidChild = 0;
long orig_rax;
int status;
int iscalling = 0;
struct user_regs_struct Regs;
pidChild = fork();
if(pidChild == 0)
{
ptrace(PTRACE_TRACEME,0,NULL,NULL);
execl("/bin/ls","ls",NULL);
printf("child exit!\r\n"); //
}else if(pidChild != -1) //parent
{
wait(&status);
if(WIFEXITED(status))
{
return 0;
}
/* ptrace(PTRACE_GETREGS,pidChild,NULL,®s);
printf("EAX == %llx,EBX == %llx,ECX == %llx,ESP == %llx\r\n",Regs.rax,Regs.rbx,Regs.rcx,Regs.rsp);
ptrace(PTRACE_CONT,pidChild,NULL,NULL);*/
ptrace(PTRACE_DETACH,pidChild,NULL,NULL);
sleep(4); //wait 4 secs,let son_process run
}
printf("exit!\r\n");
return 0;
}