Can I ptrace(2) a non-child process ?

Can I ptrace(2) a non-child process ?

Post by Ugo C » Sat, 20 Apr 1991 23:00:20

I am having problems with the ptrace(2) syscall under SunOS 4.0.3.
What I am trying to do is to read the address space of a program that
is run under a de* (gdb) from a program that is the parent of the
de*. My program runs the de*, then queries it to get the pid
of the debugged program and the address of a variable. At some point
it calls

        ptrace(PTRACE_ATTACH, pid, 0, 0, 0);

to start tracing the "grandchild" process. This calls exits with an
error of "not owner". I have also tried to call

        ptrace(PTRACE_READDATA, pid, address, size, dest);

without trying to attach the grandchild process, but I get a "no such
process" error.

TFM says that "... process does not have to be a child of the requestor ...",
but maybe there is some problem when the process to be traced is
already being traced by another process (gdb in my case). Is there any
way to circumvent these problems ? If not, how could I accomplish the
same thing (reading the address space of a program being run under a
de*) without hacking the de* source ?

Since I need this fairly quickly, even an ugly hack would do for the
moment. Please, don't suggest to instruct gdb to print out the data
then to read it from a pipe: I need to read very large arrays and this
method, although working, is far too slow.


Ugo Cei - Dipartimento Informatica e Sistemistica
          Via Abbiategrasso 209 - 27100 Pavia - ITALY   +39 382 391.372



1. How to create memory in ptraced child process w/o child source code

I am trying to allocate a new segment of memory for the child process by way
of the controlling parent process under the ptrace environment.  The
underlying premise is that I do not want to change the child's source code
(assume source code is not available).

The following peudo code should give an idea of what I want to do.

/* child */
exec()  /* execute the real child */

/* parent */
create memory in child's process and write to it.

If I can changed the child's source, I can do a shmget() and shmctl().
However, the child's source code is not available.

Can someone help?

2. konqueror (3.1) terminal window "cd" command bad

3. ??? How do I wait for a non-child process completion?

4. 2.1.119 compilation error on SPARC

5. Supervising non-child processes w/wo procfs

6. Benchmark test suite for Linux?

7. Capturing tracebacks from aborting child processes (ptrace?)

8. Intel new home network chip?

9. smail failed to reap child process: No child processes

10. how to kill a child process that runs other children processes

11. Getting a child and child's child process-id

12. waitpid for a non child process