Roland. On Thu, Apr 05, 2007 at 04:51:21PM -0700, Roland McGrath wrote: > > ptrace(PTRACE_ATTACH, 19779, 0, 0) = 0 > > --- SIGCHLD (Child exited) @ a000000000010621 (2aff00004d43) --- > > wait4(19779, 0x60000fffffb7b4b4, WUNTRACED, NULL) = -1 ECHILD (No child > > processes) > > Oh, you need __WALL if you are tracing non-main threads too. (And > technically you don't need WUNTRACED, as ptrace'd threads report in > WIFSTOPPED states regardless. But WUNTRACED does not hurt.) >
Ok. Adding __WALL indeed fixed the wait problem. In fact I had the same problem for the mainloop wait(). Note that in my case I do not know if the pid passed by user (the thread id) is that one the main or not. I would have to add code to check that. > > Well, I am using regular kill(). > > That's your problem. I assumed when you said "sent to the tid" that you > understood that kill never does this. > I meant sent to the thread I am ptracing, identified by its pid (thread id). I witched to tkill() now and with the __WALL at wait(), then I can can the signal and do my perfmon work. > > I did not know about tkill(). This one seems to accept regular pid as > > well, right? > > I don't think I understand the question. So I'll give you an answer that > probably only makes sense to me. In Linux, what's usually called "PID" is > a per-thread identifier (TID), which happens to match exactly the > per-process identifier called in Linuxspeak "TGID" (thread group ID), which > is what in the rest of the world is called a PID. When using ptrace and > wait, you are always in fact dealing with individual thread IDs. Normal > wait in the absence of ptrace refers to PIDs (whole process whose initial > thread's TID==PID). For wait on ptrace'd threads, the initial thread's TID > (the PID) behaves like other threads when that thread is stopping, but > behaves as the process-wide identifier (as in non-ptrace wait) when that > thread dies. kill sends a signal to a process by PID, as defined by POSIX. > tgkill/tkill sends a signal to a particular thread by TID. tkill is > deprecated because it is racy with PID reuse in some cases. tgkill takes > the TID of the target thread and also the TGID (PID) of the target thread > group (process) to verify that the TID was not reused. When you have > ptrace attached to a thread, its TID can only be reused after you've seen > it die with wait* or have PTRACE_DETACH'd it, or if any thread in its > process does an exec. > Ok, I think now I have added tgid/pid capture in my code, I can as well use tgkill(). Looking at the kernel header, I noticed a __WNOTHREAD. I am not clear on what this one really does. Could you explain? Thanks for your help. -- -Stephane _______________________________________________ perfmon mailing list [email protected] http://www.hpl.hp.com/hosted/linux/mail-archives/perfmon/
