2

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.

7

Easy enough to do: ps -eLf | grep java

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

6

You can launch:

ps -o nlwp PID

(PID will be the pid of your process)

nlwp = number of lightweight process

  • Do this really give numberof active threads ? – Balaji Boggaram Ramanarayan Feb 28 '16 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 '16 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 '16 at 17:33
3

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 or htop, then you can type H (capital) to toggle display of threads. Its worth looking at the various top keystrokes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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