Hi all,

I need help trying to wrap my head around ptrace. I'm trying to create the most basic of programs:


in the child process (right after the fork) I do:

       ptrace(PTRACE_TRACEME);

       printf("Being traced\n");

       execve(argv[opt_offset], argv+opt_offset, env);
       exit(1);

In the parent I do:

   pid_t ret=waitpid(first_child, &status, 0);

   ptrace( PTRACE_DETACH, ret );

   ret=waitpid(first_child, &status, 0);


Instead of DETACH I already tried PTRACE_CONT and PTRACE_SYSCALL.


What I expect to happen is that the child should run what I tell it to (I tell it to run "echo hi"), and be caught with both waits. Instead, the first wait catches a signal 5 (TRAP, as expected), but the second wait hangs forever AND THE ECHO DOES NOT RUN!!


Also of interest is that when I added the "printf" after the TRACEME, that printf gets executed (output goes to the console) before the first wait at the parent. In other words, the program is not being traced immediately.


I need help figuring out what the !*(#()@! is going on here.


Thanks,

Shachar


P.s.

Please do not send me to read strace's source code for reference. Strace's source code is so twisted I cannot understand how ANYONE can figure out what's going on there, and that's before mentioning the #ifdefs


Sh.


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to