Understanding Java and PIDs on Linux

Discussion in 'Java' started by Chris, Sep 7, 2004.

  1. Chris

    Chris Guest

    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");
    }
    }
     
    Chris, Sep 7, 2004
    #1
    1. Advertising

  2. Chris

    Chris Guest

    > > 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.


    No -- the "ShortWait" program in my message did not create any threads.
     
    Chris, Sep 7, 2004
    #2
    1. Advertising

  3. "Chris" <> writes:

    > 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.
     
    Tor Iver Wilhelmsen, Sep 7, 2004
    #3
  4. Chris wrote:
    >>Presumably you get one process in the list per thread created.

    >
    > 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.)
     
    Michael Borgwardt, Sep 7, 2004
    #4
  5. Chris

    Chris Uppal Guest

    Michael Borgwardt wrote:

    > 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
     
    Chris Uppal, Sep 8, 2004
    #5
  6. Chris

    Liz Guest

    "Chris Uppal" <-THIS.org> wrote in message
    news:p...
    > Michael Borgwardt wrote:
    >
    > > 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.


    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

    >
    > 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
    >
    >
     
    Liz, Sep 8, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    3
    Views:
    671
    Robert Olofsson
    Jan 7, 2004
  2. Manish Hatwalne

    Understanding error - Java returned: 137

    Manish Hatwalne, Sep 3, 2004, in forum: Java
    Replies:
    1
    Views:
    7,334
    Thomas Fritsch
    Sep 3, 2004
  3. skip
    Replies:
    3
    Views:
    451
  4. Replies:
    2
    Views:
    366
  5. Chuck Bearden
    Replies:
    2
    Views:
    818
    Chuck Bearden
    May 3, 2010
Loading...

Share This Page