How to check Threads of any process in Linux

View threads of a process in Linux Server.

Do you know we can also check thread details on Linux System Level via using multiple commands. Let me show you it with example.

  1. You can use  ps command we have “-T” Option which will show you threads view,
    eg: ps -T -p 11629
    PID SPID TTY TIME CMD
    11629 11629 ? 00:00:00 java
    11629 11631 ? 00:00:01 DestroyJavaVM h
    11629 11632 ? 00:00:00 Signal Reporter
    11629 11633 ? 00:00:09 JIT Compilation
    11629 11634 ? 00:00:04 JIT Compilation
    11629 11635 ? 00:00:00 JIT Compilation
    11629 11636 ? 00:00:00 JIT Compilation
    11629 11637 ? 00:00:00 JIT Compilation
    11629 11638 ? 00:00:00 JIT Sampler

Here we have “ps” command “-T” for thread view and “-p” for process.

SPID is the Thread ID here in that Output.

And CMD is the Thread name.

You can find all threads on system via using Below options:

 

  • eg:
    ps -eT | grep -i “java”
    in that example we have    “-e” for all process, “-T” for threads grep it via java threads name.

For extended Output you can use below command with “l” (el) as well :

ps -lT -p 11629

F S UID PID SPID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 500 11629 11629 11616 0 80 0 – 708693 futex_ ? 00:00:00 java
1 S 500 11629 11631 11616 0 80 0 – 708693 futex_ ? 00:00:01 DestroyJavaVM h

 

If you want to go ahead more in deep you can use with status of thread you can check it in :

  • cat /proc/process_id/status
    eg : cat /proc/status
  • cat /proc/process_id/task/thread_id/status 
    eg : cat /proc/11629/task/11631/status
  • For checking number of running threads you can use it like
    eg : ps huH -p 11629 | wc -l
    28

 

 

2. You can use pstree command for same purpose.

  • pstree -p <porcess_id>
    eg :
    pstree -p 11629
    java(11629)─┬─{java}(11631)
    ├─{java}(11632)
    ├─{java}(11633)
    ├─{java}(11634)
    ├─{java}(11635)
    ├─{java}(11636)
    ├─{java}(11637)

3. Next Command is TOP

  • top -H command
    eg:
Top Thread
Top Command with threads

You can specifically check one process threads like below command:

top -H -p 11629

 

Process wise

 

 

 

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *