[ale] differentiating processes from threads

Danny Cox danscox at mindspring.com
Tue Apr 2 11:18:13 EST 2002


John,

On Tue, 2002-04-02 at 04:32, John Wells wrote:
> Hmmm...
> 
> Ok, so to test this we should be able to:
> 
> perl -e 'fork();<STDIN>;'
> 
> Shouldn't this do a true fork?  If so, then look at the output of:
> 
> ps -eo pid,pgid,flags,user,args | grep perl
> 
> 30213 30213 000 jbw      perl -e fork();<STDIN>;
> 30214 30213 040 jbw      perl -e fork();<STDIN>;
> 
> The second process still has the FORKNOEXEC flags set?!?

	Yes, that's correct.  The process has forked, but it's not execed
anything.  The '040' flag simply means that no exec(2) system call has
been performed, but a fork(2) has.  The above test shows nothing about
thread possibilities.  It was just something I noticed with mozilla, and
will be true of any threads.  While the vast majority of forks will exec
soon thereafter, a thread necessarily will not.

	Unfortunatly, this isn't really a property of threads, but a
consequence.  Other processes, like the one you discovered, can also
have the same flag set.  I see no direct way of testing a PID for
'threadness' ('thread-nature' Hmm.  Zen anyone?).  The necessary flags
just aren't exposed in /proc/<pid> to tell.  This is most likely why ps
can't tell that threads N,M,O are sharing the same memory, and must show
it twice.

	However, this does present a possibility: hack the kernel where it
displays the strings for "/proc/<pid>/status".  It would just be one
more line, I think.  Of course, you'd have to find which member(s) of
the task struct represented 'threadness', but then it's dead easy.

-- 
kernel, n.: A part of an operating system that preserves the
medieval traditions of sorcery and black art.

Danny


---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list