|
Question: I am running a program that runs in multiple threads will be derived. I want to know how many there will be threaded programs at runtime. What is the number of threads in the inspection process of Linux the easiest way?
If you want to see the number of threads per process in Linux, there are several ways to do this.
Method one: / proc
proc pseudo file system, which resides in the / proc directory, which is the easiest way to view any active process threads. / Proc directory in readable text file output, existing processes and systems to provide hardware-related information such as CPU, memory, disk, and so on.
$ Cat / proc / < pid > / status
Process < pid > For more information, including the status of the process (for example, sleeping, running), the number of the parent process PID, UID, GID, use file descriptors, and the number of context switches above command will be displayed. Output also includes the total number of threads created by the process shown below.
Threads: < N >
For example, check the number of threads process PID 20571:
$ Cat / proc / 20571 / status
It shows that the process has 28 threads.
Or, you can simply the number in / proc // task statistics subdirectories, as shown below.
$ Ls / proc / < pid > / task | wc
This is because, for each thread in a process created in the / proc / < pid > / task will be created in the appropriate directory, named for its thread ID. Thus the / proc / / task directory indicates the number of the total number in the process threads.
Method Two: ps
If you are a loyal user powerful ps command, this command can also tell you that a process (with "H" option) number of threads. The following command will output the number of threads of a process. "H" in front of the desired option.
$ Ps hH p < pid > | wc-l |
|
|
|