I am trying to do the following:
single step a ptraced thread.
wait fro the singlestep to end.
I do
ptrace(PTRACE_SINGLESTEP, pid, 0,0);
int child = waitpid(pid, &status,, WUNTRACED);

problem is that some of the time I get:

child = -1 and errno=ECHILD

I dont know why sine I believe I am the only thread waithing for this pid

Anyway some of the time the thread just hasnt finished the single step and trying to use ptrace after the trace fails.

To overcome this I put an artificial "wait" which seems to work
struct user_regs_struct regs;
do {
ptrace(PTRACE_GETREGS, _activePid, &regs, 0) ;
} while(ptrace(PTRACE_PEEKDATA, _activePid, regs.eip, 0) ==-1);

basically using busy ptrace to determine that the thread has stopped (otherwise ptrace fails).

I would appreciate if anyone can shed light on how exactly wait and ptrace work together. I have other places in my code where I have these spurious problems which I am putting similar hacks to.
Thanks,
Danny