debugging threads vs processes

Per Bothner per@bothner.com
Thu Jul 12 17:17:00 GMT 2001


(Slightly off-topic, I admit ...)

I'm trying to debug Java modules loaded into Apache 2.
Thing seem to work ok with the "prefork" module, but when
I configure Apache with the "threaded" module I can only
"reload" a few dozen times before the server freezes.
While trying to figure out what is going on, I'm getting
a bit confused wrt process ids vs thread ids.

One problem is how I can get a list of running processes vs threads?
On my RedHat 7.1 (Pentium3) ps -m says "Thread display not
implemented."  My impression is that both ps and top
list all threads, not just all processes.  This is my
conclusion from looking at various 'top' displays which show
a bunch of "processes" using more memory in lock-step,
which only seems plausible of these "processes" are
actually threads in the same process.  But it sure would be
nice to have a way of showing threads vs processes more clearly.

Another confusing thing is that getpid seems to return s thread id,
not a process id.  What leads me to believe this is the following
debug output from running Apache: (Each line results from one request
to the server from the browser.)

handle: text/html, pid:16694,prev:0, created:0
handle: text/html, pid:16694,prev:16694, created:1
handle: text/html, pid:16694,prev:16694, created:1
handle: text/html, pid:16697,prev:16694, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1
handle: text/html, pid:16697,prev:16697, created:1

The pid field is the result of getpid(), the prev field is the value
saved by the last request in a static variable.  ps -H claims that
16694 and 16697 are siblings, not parent/child.  But then how can
16697 remember a static value set by 16694?  Unless they are two
threads in the same process, in which case getpid is returning the
thread id, rather than a process id.

Does someone on this list understand Linux threads enough to explain
what is going on and/or suggest useful debugging tools?
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/



More information about the Java mailing list