Understanding Java and PIDs on Linux

C

Chris

When I run a Java program on Linux, it spins off a large, random number of
processes. When I call ps -ef to show all processes, I get output like this:

<snip>
root 6920 6694 8 13:01 pts/6 00:00:00 java ShortWait
root 6921 6920 0 13:01 pts/6 00:00:00 java ShortWait
root 6922 6921 0 13:01 pts/6 00:00:00 java ShortWait
root 6923 6921 0 13:01 pts/6 00:00:00 java ShortWait
root 6924 6921 0 13:01 pts/6 00:00:00 java ShortWait
root 6925 6921 0 13:01 pts/6 00:00:00 java ShortWait
root 6926 6921 0 13:01 pts/6 00:00:00 java ShortWait
root 6927 6921 0 13:01 pts/6 00:00:00 java ShortWait
root 6928 6921 0 13:01 pts/6 00:00:00 java ShortWait
<snip>

Can someone explain why there are so many PIDs? Or maybe I don't understand
what a PID is.

The program I'm running above is just a simple class to demonstrate the
problem:
public class ShortWait {
public static void main(String[] args) throws Exception {
System.out.println("start");
Thread.sleep(10000);
System.out.println("end");
}
}
 
C

Chris

Can someone explain why there are so many PIDs? Or maybe I don't
understand
Presumably you get one process in the list per thread created.

No -- the "ShortWait" program in my message did not create any threads.
 
T

Tor Iver Wilhelmsen

Chris said:
Can someone explain why there are so many PIDs? Or maybe I don't understand
what a PID is.

Presumably you get one process in the list per thread created.
 
M

Michael Borgwardt

Chris said:
No -- the "ShortWait" program in my message did not create any threads.

What gives you the idea that there can be only those threads you
create explicitly? The JVM also uses threads for its own use, e.g
for garbage collection.

BTW, this is not a sign that Java on linux is wasteful; Linux assigns
separate process IDs both to "real processes" and lightweight threads
(without a separate environment, address space, etc.)
 
C

Chris Uppal

Michael said:
What gives you the idea that there can be only those threads you
create explicitly? The JVM also uses threads for its own use, e.g
for garbage collection.

But nine seems excesive for a simple program with no explicit threads and no
AWT event loop.

Let's see. There is the main thread (the one running main). There may be a GC
thread. There may/should be a finaliser thread. Perhaps there's a JIT
optimiser thread. Um... No that's all I can think of.

So I'd be interested to know what the other threads are doing, too. Perhaps
this implementation uses some sort of pool of OS threads as part of its
implementation of Java threads ?

Which JVM is it anyway ? Sun's, IBM's, ...

-- chris
 
L

Liz

Chris Uppal said:
But nine seems excesive for a simple program with no explicit threads and no
AWT event loop.

I have a simple application that has a button that when clicked on
it prints out all the threads in the current thread group. I don't
start any threads in my application. Here's what I get
(d means daemon, * means current, number is priority) The JVM seems
to have 9 (or more) threads for itself in the system group.

Thread Group: system
------ 1
Thread 0: d 10 Reference Handler
Thread 1: d 8 Finalizer
Thread 2: d 10 Signal Dispatcher
Thread 3: d 10 CompilerThread0
Thread 4: d 6 AWT-Windows
Thread 5: * 6 AWT-EventQueue-0
Thread 6: 5 AWT-Shutdown
Thread 7: d 10 Java2D Disposer
Thread 8: 5 DestroyJavaVM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top