clone on Linux

Ganesan Rajagopal rganesan at novell.com
Tue Jan 2 09:38:38 UTC 2001


On Tue, Dec 19, 2000 at 02:55:20PM -0600, Mike Coleman wrote:

> You might want to take a look at SUBTERFUGUE (see subterfugue.org).  It can
> trace cloned processes (there are probably some bugs, but it basically works),
> so you could examine it to figure out ways to add this to strace.  SUBTERFUGUE
> itself has in principle a superset of strace capabilities, but there are a lot
> of things missing from its tracing capabilities and it's currently a lot
> slower than strace.

Thank you! This has been *very* helpful. I could get SUBTERFUGUE working
very nicely with a test pthreads program. Though I am only a beginning
Python programmer I am able to follow the code in p_linux_i386_trick.py
(which I assume has the relevant code). I would like to add this support to
strace if no one is duplicating the effort already (Wichert, is anyone
actively working on fixing clone support for strace?).

> 
> > * Did clone support work at any point of time with any Linux 2.2* kernel?
> >   Are there any kernel patches floating around? Is this easier to get
> >   working with 2.4 kernels? 
> 
> Pre-2.4 kernels will be much harder, I think.  Take a look at the SUBTERFUGUE
> patch page to get an idea of what's missing in pre-2.4 kernels.  If it was me,
> I'd stick with 2.4.

This has been very helpful too. Since 2.4 is already in pre-release I guess
I'll stick with 2.4 for now. 

> > * Is it possible to support cloned processes sanely *after* they have been 
> >   started (by using strace -p).
> 
> I can't see why not.  That's not to say that it will be easy.

I guess you can do a PTRACE_GETPPID call to get the parent of a cloned
process. However it will probably take a lot more work to get a list of all
the cloned processes for this parent. By the way, are you working on adding
support for attaching to an existing process using SUBTERFUGUE?

My problem is that I have a fairly large pthreads program that is behaving
perfectly fine on other platforms but on Linux shows heavy CPU usage
periodically. I badly need the ability to see what exactly is happening at
that instant. 

Any way, coming back to strace, when I have been debugging strace with
multi-threaded programs in two scenarios. When the program is started under
strace control, strace doesn't trace the cloned processes without the -f
option. With the -f option both strace hangs in a wait4() call. Calling
strace with a -p option doesn't seem to do anything useful. I am still
debugging this.

Looking at the strace code, it appears that strace explicitly sets a break
point after a fork()/clone() and then removes it later. It also converts a
vfork() into a fork(). SUBTERFUGUE instead appears to translate fork() and
vfork() into a clone call with CLONE_PTRACE flag set. I can't find any
information if CLONE_PTRACE also automatically sends a SIGSTOP to the child.

Finally, what happens when you PTRACE_ATTACH to a cloned process? Does it
automatically set CLONE_PTRACE flag for that process?

Ganesan

-- 
R. Ganesan (rganesan at novell.com)       | Ph: 91-80-5721856 Ext: 2149
Novell India Development Center.       | #include <std_disclaimer.h>





More information about the Strace-devel mailing list