How to get (from terminal) total number of threads (per process and total for all processes)
I tried googling it, but I can't find it. I am looking for:
number of threads in process X
total number of threads running currently
system-info
add a comment |
I tried googling it, but I can't find it. I am looking for:
number of threads in process X
total number of threads running currently
system-info
stackoverflow.com/questions/268680/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 3 '15 at 17:15
add a comment |
I tried googling it, but I can't find it. I am looking for:
number of threads in process X
total number of threads running currently
system-info
I tried googling it, but I can't find it. I am looking for:
number of threads in process X
total number of threads running currently
system-info
system-info
edited Dec 19 '11 at 18:24
enzotib
63.2k6133154
63.2k6133154
asked Dec 19 '11 at 14:16
NoSenseEtAlNoSenseEtAl
2031310
2031310
stackoverflow.com/questions/268680/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 3 '15 at 17:15
add a comment |
stackoverflow.com/questions/268680/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 3 '15 at 17:15
stackoverflow.com/questions/268680/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 3 '15 at 17:15
stackoverflow.com/questions/268680/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 3 '15 at 17:15
add a comment |
5 Answers
5
active
oldest
votes
To get the number of threads for a given pid:
ps -o nlwp <pid>
To the get the sum of all threads running in the system:
ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
1
ps -o nlwp <pid>
returns NLWP :), what does that mean ?
– Siddharth
May 4 '13 at 5:12
1
@Siddharth NLWP stands for Number of LightWeight Processes which is the number of threads.
– jcollado
May 7 '13 at 2:45
You can suppress the "NLWP" with "h" (hide headers); ie:ps h -o nlwp $pid
– bufh
Aug 9 '16 at 9:00
add a comment |
For finding the number of threads running a single process you can look at /proc/<pid>/status
. It should list the number of threads as one of the fields.
add a comment |
I'm basing this answer around ps axms
. ps
is a great tool for listing what's running.
If you want to filter that by a process, you could try something like this:
echo $(( `ps axms | grep firefox | wc -l` - 1))
We subtract 1 because grep will show in that list.
For all threads in general this should work:
echo $(( `ps axms | wc -l` - 1))
We subtract one this time because there is a header row.
This is inaccurate, as it reports an extra thread per process
– Score_Under
2 days ago
add a comment |
To get the total number of the threads(tiny pieces of a process running simultaneously) of a you can use the command ps -o nlwp <pid>
It works all the time.
But if you prefer to try to see it through a file. you should probably look at the files that were created for each and every process of the system. There you can get the ultimate details of the process. For each and every process, there is a folder created in /proc/<pid>
there you can see all the other details also.
add a comment |
On linux specifically, here is one way to do it per-process:
#!/bin/sh
while read name val; do
if [ "$name" = Threads: ]; then
printf %s\n "$val"
return
fi
done < /proc/"$1"/status
You may then invoke this script with a PID as an argument, and it will report the number of threads owned by that process.
To get the thread count for the whole system, this suffices:
#!/bin/sh
count() {
printf %s\n "$#"
}
count /proc/[0-9]*/task/[0-9]*
These approaches may seem a little unorthodox in that they rely heavily on shell features, but in return both of them are faster than the corresponding ps
and awk
-based approaches on my machine (while also not creating extra threads of their own for pipes). Bear in mind that the shell launched to run these scripts will have a thread of its own (or more, if you are using a strange implementation).
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f88972%2fhow-to-get-from-terminal-total-number-of-threads-per-process-and-total-for-al%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
To get the number of threads for a given pid:
ps -o nlwp <pid>
To the get the sum of all threads running in the system:
ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
1
ps -o nlwp <pid>
returns NLWP :), what does that mean ?
– Siddharth
May 4 '13 at 5:12
1
@Siddharth NLWP stands for Number of LightWeight Processes which is the number of threads.
– jcollado
May 7 '13 at 2:45
You can suppress the "NLWP" with "h" (hide headers); ie:ps h -o nlwp $pid
– bufh
Aug 9 '16 at 9:00
add a comment |
To get the number of threads for a given pid:
ps -o nlwp <pid>
To the get the sum of all threads running in the system:
ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
1
ps -o nlwp <pid>
returns NLWP :), what does that mean ?
– Siddharth
May 4 '13 at 5:12
1
@Siddharth NLWP stands for Number of LightWeight Processes which is the number of threads.
– jcollado
May 7 '13 at 2:45
You can suppress the "NLWP" with "h" (hide headers); ie:ps h -o nlwp $pid
– bufh
Aug 9 '16 at 9:00
add a comment |
To get the number of threads for a given pid:
ps -o nlwp <pid>
To the get the sum of all threads running in the system:
ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
To get the number of threads for a given pid:
ps -o nlwp <pid>
To the get the sum of all threads running in the system:
ps -eo nlwp | tail -n +2 | awk '{ num_threads += $1 } END { print num_threads }'
answered Dec 19 '11 at 14:41
jcolladojcollado
7,11811923
7,11811923
1
ps -o nlwp <pid>
returns NLWP :), what does that mean ?
– Siddharth
May 4 '13 at 5:12
1
@Siddharth NLWP stands for Number of LightWeight Processes which is the number of threads.
– jcollado
May 7 '13 at 2:45
You can suppress the "NLWP" with "h" (hide headers); ie:ps h -o nlwp $pid
– bufh
Aug 9 '16 at 9:00
add a comment |
1
ps -o nlwp <pid>
returns NLWP :), what does that mean ?
– Siddharth
May 4 '13 at 5:12
1
@Siddharth NLWP stands for Number of LightWeight Processes which is the number of threads.
– jcollado
May 7 '13 at 2:45
You can suppress the "NLWP" with "h" (hide headers); ie:ps h -o nlwp $pid
– bufh
Aug 9 '16 at 9:00
1
1
ps -o nlwp <pid>
returns NLWP :), what does that mean ?– Siddharth
May 4 '13 at 5:12
ps -o nlwp <pid>
returns NLWP :), what does that mean ?– Siddharth
May 4 '13 at 5:12
1
1
@Siddharth NLWP stands for Number of LightWeight Processes which is the number of threads.
– jcollado
May 7 '13 at 2:45
@Siddharth NLWP stands for Number of LightWeight Processes which is the number of threads.
– jcollado
May 7 '13 at 2:45
You can suppress the "NLWP" with "h" (hide headers); ie:
ps h -o nlwp $pid
– bufh
Aug 9 '16 at 9:00
You can suppress the "NLWP" with "h" (hide headers); ie:
ps h -o nlwp $pid
– bufh
Aug 9 '16 at 9:00
add a comment |
For finding the number of threads running a single process you can look at /proc/<pid>/status
. It should list the number of threads as one of the fields.
add a comment |
For finding the number of threads running a single process you can look at /proc/<pid>/status
. It should list the number of threads as one of the fields.
add a comment |
For finding the number of threads running a single process you can look at /proc/<pid>/status
. It should list the number of threads as one of the fields.
For finding the number of threads running a single process you can look at /proc/<pid>/status
. It should list the number of threads as one of the fields.
edited Feb 28 '14 at 0:36
Eric Carvalho
41.6k17115146
41.6k17115146
answered Feb 28 '14 at 0:15
anaken78anaken78
7112
7112
add a comment |
add a comment |
I'm basing this answer around ps axms
. ps
is a great tool for listing what's running.
If you want to filter that by a process, you could try something like this:
echo $(( `ps axms | grep firefox | wc -l` - 1))
We subtract 1 because grep will show in that list.
For all threads in general this should work:
echo $(( `ps axms | wc -l` - 1))
We subtract one this time because there is a header row.
This is inaccurate, as it reports an extra thread per process
– Score_Under
2 days ago
add a comment |
I'm basing this answer around ps axms
. ps
is a great tool for listing what's running.
If you want to filter that by a process, you could try something like this:
echo $(( `ps axms | grep firefox | wc -l` - 1))
We subtract 1 because grep will show in that list.
For all threads in general this should work:
echo $(( `ps axms | wc -l` - 1))
We subtract one this time because there is a header row.
This is inaccurate, as it reports an extra thread per process
– Score_Under
2 days ago
add a comment |
I'm basing this answer around ps axms
. ps
is a great tool for listing what's running.
If you want to filter that by a process, you could try something like this:
echo $(( `ps axms | grep firefox | wc -l` - 1))
We subtract 1 because grep will show in that list.
For all threads in general this should work:
echo $(( `ps axms | wc -l` - 1))
We subtract one this time because there is a header row.
I'm basing this answer around ps axms
. ps
is a great tool for listing what's running.
If you want to filter that by a process, you could try something like this:
echo $(( `ps axms | grep firefox | wc -l` - 1))
We subtract 1 because grep will show in that list.
For all threads in general this should work:
echo $(( `ps axms | wc -l` - 1))
We subtract one this time because there is a header row.
answered Dec 19 '11 at 14:31
Oli♦Oli
221k86561763
221k86561763
This is inaccurate, as it reports an extra thread per process
– Score_Under
2 days ago
add a comment |
This is inaccurate, as it reports an extra thread per process
– Score_Under
2 days ago
This is inaccurate, as it reports an extra thread per process
– Score_Under
2 days ago
This is inaccurate, as it reports an extra thread per process
– Score_Under
2 days ago
add a comment |
To get the total number of the threads(tiny pieces of a process running simultaneously) of a you can use the command ps -o nlwp <pid>
It works all the time.
But if you prefer to try to see it through a file. you should probably look at the files that were created for each and every process of the system. There you can get the ultimate details of the process. For each and every process, there is a folder created in /proc/<pid>
there you can see all the other details also.
add a comment |
To get the total number of the threads(tiny pieces of a process running simultaneously) of a you can use the command ps -o nlwp <pid>
It works all the time.
But if you prefer to try to see it through a file. you should probably look at the files that were created for each and every process of the system. There you can get the ultimate details of the process. For each and every process, there is a folder created in /proc/<pid>
there you can see all the other details also.
add a comment |
To get the total number of the threads(tiny pieces of a process running simultaneously) of a you can use the command ps -o nlwp <pid>
It works all the time.
But if you prefer to try to see it through a file. you should probably look at the files that were created for each and every process of the system. There you can get the ultimate details of the process. For each and every process, there is a folder created in /proc/<pid>
there you can see all the other details also.
To get the total number of the threads(tiny pieces of a process running simultaneously) of a you can use the command ps -o nlwp <pid>
It works all the time.
But if you prefer to try to see it through a file. you should probably look at the files that were created for each and every process of the system. There you can get the ultimate details of the process. For each and every process, there is a folder created in /proc/<pid>
there you can see all the other details also.
answered Sep 21 '15 at 7:02
LaksithLaksith
1396
1396
add a comment |
add a comment |
On linux specifically, here is one way to do it per-process:
#!/bin/sh
while read name val; do
if [ "$name" = Threads: ]; then
printf %s\n "$val"
return
fi
done < /proc/"$1"/status
You may then invoke this script with a PID as an argument, and it will report the number of threads owned by that process.
To get the thread count for the whole system, this suffices:
#!/bin/sh
count() {
printf %s\n "$#"
}
count /proc/[0-9]*/task/[0-9]*
These approaches may seem a little unorthodox in that they rely heavily on shell features, but in return both of them are faster than the corresponding ps
and awk
-based approaches on my machine (while also not creating extra threads of their own for pipes). Bear in mind that the shell launched to run these scripts will have a thread of its own (or more, if you are using a strange implementation).
add a comment |
On linux specifically, here is one way to do it per-process:
#!/bin/sh
while read name val; do
if [ "$name" = Threads: ]; then
printf %s\n "$val"
return
fi
done < /proc/"$1"/status
You may then invoke this script with a PID as an argument, and it will report the number of threads owned by that process.
To get the thread count for the whole system, this suffices:
#!/bin/sh
count() {
printf %s\n "$#"
}
count /proc/[0-9]*/task/[0-9]*
These approaches may seem a little unorthodox in that they rely heavily on shell features, but in return both of them are faster than the corresponding ps
and awk
-based approaches on my machine (while also not creating extra threads of their own for pipes). Bear in mind that the shell launched to run these scripts will have a thread of its own (or more, if you are using a strange implementation).
add a comment |
On linux specifically, here is one way to do it per-process:
#!/bin/sh
while read name val; do
if [ "$name" = Threads: ]; then
printf %s\n "$val"
return
fi
done < /proc/"$1"/status
You may then invoke this script with a PID as an argument, and it will report the number of threads owned by that process.
To get the thread count for the whole system, this suffices:
#!/bin/sh
count() {
printf %s\n "$#"
}
count /proc/[0-9]*/task/[0-9]*
These approaches may seem a little unorthodox in that they rely heavily on shell features, but in return both of them are faster than the corresponding ps
and awk
-based approaches on my machine (while also not creating extra threads of their own for pipes). Bear in mind that the shell launched to run these scripts will have a thread of its own (or more, if you are using a strange implementation).
On linux specifically, here is one way to do it per-process:
#!/bin/sh
while read name val; do
if [ "$name" = Threads: ]; then
printf %s\n "$val"
return
fi
done < /proc/"$1"/status
You may then invoke this script with a PID as an argument, and it will report the number of threads owned by that process.
To get the thread count for the whole system, this suffices:
#!/bin/sh
count() {
printf %s\n "$#"
}
count /proc/[0-9]*/task/[0-9]*
These approaches may seem a little unorthodox in that they rely heavily on shell features, but in return both of them are faster than the corresponding ps
and awk
-based approaches on my machine (while also not creating extra threads of their own for pipes). Bear in mind that the shell launched to run these scripts will have a thread of its own (or more, if you are using a strange implementation).
edited 2 days ago
answered 2 days ago
Score_UnderScore_Under
32415
32415
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f88972%2fhow-to-get-from-terminal-total-number-of-threads-per-process-and-total-for-al%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/questions/268680/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 3 '15 at 17:15