No such process - ptrace

Problem Description : Program C consists of a loop. The execution of this program should be controlled by another process, which will periodically display the progress of the monitored process. After kill(pid, SIGSTOP), the ptrace(PTRACE_PEEKTEXT,pid,...) function ptrace(PTRACE_PEEKTEXT,pid,...) no longer finds process C. From what I read, ptrace(PTRACE_PEEKTEXT,pid,... ) should work when the process identified by pid stopped.

I don’t know what exactly I am missing, so any help would be greatly appreciated. The following is what I have done so far:

There are two processes: P and C.

The first process (P) creates the second (C) via fork () .

C code looks like this:

 int i = 0; int main() { ptrace(PTRACE_TRACEME, 0, NULL, NULL); printf("Memory address = %p", (void *)&i); while(1) { i++;} } 

P code below:

 {...} switch (pid = fork()) { case 0: /* the child */ if (execl("C", "", (char *) NULL) == -1) { perror("execl"); } break; case -1: /* Error */ perror("fork"); exit(EXIT_FAILURE); default: /* the parent */ sleep(1); kill(pid, SIGSTOP); wait(&status); if (WSTOPSIG(status)==SIGSTOP) { printf("%s","Child was interrupted. Insert memory address\n"); scanf("%p",&address); printf("Address = %p", address); data = ptrace(PTRACE_PEEKTEXT, pid, address,NULL); if(data==-1){ if(errno){ printf("%s\n","Error at PEEKTEXT\n"); printf("%s\n",strerror(errno)); } if(errno == ESRCH){ printf("%s\n","ESRCH error\n"); } if(errno == EIO){ printf("%s\n","EIO error\n"); } } printf("***Data retrieved is: %ld\n",data); data = ptrace(PTRACE_CONT, pid, 0, 0); } if(WIFEXITED(status)){ printf("[Parent] - Child exit status is: %d \n", WEXITSTATUS(status)); break; } break; } {...} 

Conclusion:

  • From C: Memory Address = 0x60104c
  • From P: The child was interrupted. Paste in the memory address (next I insert that typed C)

Address = 0x60104c

And the error :

Error with PEEKTEXT

No such process

ERROR ESRCH

*** Received data: -1

+5
source share
1 answer

Verify that the address variable is of the correct type. I tried with void * address and it worked for me as well. I got your error using int for an address variable

+5
source

Source: https://habr.com/ru/post/1204945/


All Articles