Re: [patch] Fix Linux attach to signalled/stopped processes

Roland McGrath
2008-04-12T00:02:32Z

> There is a race if:
> * inferior was not stopped (a regular running process)

Ah, right. You can also do:

PTRACE_ATTACH -> pending SIGSTOP
... if running -> stopped, no pending SIGSTOP
... if stopped -> still stopped, pending SIGSTOP
tkill (SIGSTOP, tid) -> pending SIGSTOP

PTRACE_CONT, tid, 0 -> if not stopped the first time yet, ESRCH
-> if stopped, wakes up, dequeues SIGSTOP
wait -> always see it stop

You just don't know whether you'll see one more spurious SIGSTOP or not.
(Once you've waited, you can synchronously check /proc, but that doesn't
tell you whether it was your spurious one or just an outside one sent
right now.)

Thanks,
Roland