Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my Linux server I run tomcat as root and when I run ps aux it gives the following output.

root     25667  0.1 29.2 4574004 306980 ?      Sl   Apr27  33:57 /usr/local/java/bin/java -Djava.util.logging.config.file...

Thre is only parent process, but when I run htop I can see all other child process (which are threads?). Sample output for a few lines given below.

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                              
25668 root       15   0 4466M  299M 14208 S  0.0 29.3  0:01.23 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t
25669 root       18   0 4466M  299M 14208 S  0.0 29.3  0:54.84 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t
25670 root       15   0 4466M  299M 14208 S  0.0 29.3  0:00.25 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t
25671 root       15   0 4466M  299M 14208 S  0.0 29.3  0:00.54 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t
25672 root       18   0 4466M  299M 14208 S  0.0 29.3  0:00.00 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t
25673 root       15   0 4466M  299M 14208 S  0.0 29.3  0:17.96 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t
25674 root       15   0 4466M  299M 14208 S  0.0 29.3  0:20.01 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t
25675 root       19   0 4466M  299M 14208 S  0.0 29.3  0:00.00 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/t

So I want to get child process list with a single command. I set maxThreads to 200 in config file, and want to check current thread count by counting child threads.

share|improve this question
up vote 3 down vote accepted

Easy enough to do: ps -eLf | grep java

Might have to adjust (grep can be refined to get what you're looking for).

share|improve this answer

You can launch:

ps -o nlwp PID

(PID will be the pid of your process)

nlwp = number of lightweight process

share|improve this answer
Do this really give numberof active threads ? – Balaji Boggaram Ramanarayan Feb 28 at 23:28
Yes. NLWP means number of light-weight processes which is precisely the number of threads the process is currently using. – agiannetti Mar 18 at 16:45
Sorry, I meant to ask running threads (which are actively doing work), and not the idle ones – Balaji Boggaram Ramanarayan Mar 18 at 17:33

If you have a JDK installed, one very useful way of monitoring this (and the various heaps sizes) in real-time is jconsole, which is a GUI program (if you have javac, you should also have this). There are also things like jstat and jinfo and others. To benefit from jconsole, you may need to enable JMX (this can also be done for remote connections). You'll need to run these tools as the same user that is running the JVM you want to inspect.

If you're using top, then you can type h to toggle display of threads. Its worth looking at the various top keystrokes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.