Are tgid and pid ever different for a process or lightweight process?
Clash Royale CLAN TAG#URR8PPP
tgid and pid are the same concept for any process or for any lightweight process.
In /proc/$pid/status
, tgid and pid are distinct fields. Are tgid and pid ever different for a process or lightweight process?
Thanks.
linux linux-kernel process thread
add a comment |
tgid and pid are the same concept for any process or for any lightweight process.
In /proc/$pid/status
, tgid and pid are distinct fields. Are tgid and pid ever different for a process or lightweight process?
Thanks.
linux linux-kernel process thread
This has a good explanation when that can happen.
– std_unordered_map
Dec 31 '18 at 5:25
1
man7.org/linux/man-pages/man5/proc.5.html It's just kernel name things a little bit weird.
– 炸鱼薯条德里克
Dec 31 '18 at 7:15
add a comment |
tgid and pid are the same concept for any process or for any lightweight process.
In /proc/$pid/status
, tgid and pid are distinct fields. Are tgid and pid ever different for a process or lightweight process?
Thanks.
linux linux-kernel process thread
tgid and pid are the same concept for any process or for any lightweight process.
In /proc/$pid/status
, tgid and pid are distinct fields. Are tgid and pid ever different for a process or lightweight process?
Thanks.
linux linux-kernel process thread
linux linux-kernel process thread
edited Dec 31 '18 at 5:12
Tim
asked Dec 31 '18 at 4:57
TimTim
26.3k75247457
26.3k75247457
This has a good explanation when that can happen.
– std_unordered_map
Dec 31 '18 at 5:25
1
man7.org/linux/man-pages/man5/proc.5.html It's just kernel name things a little bit weird.
– 炸鱼薯条德里克
Dec 31 '18 at 7:15
add a comment |
This has a good explanation when that can happen.
– std_unordered_map
Dec 31 '18 at 5:25
1
man7.org/linux/man-pages/man5/proc.5.html It's just kernel name things a little bit weird.
– 炸鱼薯条德里克
Dec 31 '18 at 7:15
This has a good explanation when that can happen.
– std_unordered_map
Dec 31 '18 at 5:25
This has a good explanation when that can happen.
– std_unordered_map
Dec 31 '18 at 5:25
1
1
man7.org/linux/man-pages/man5/proc.5.html It's just kernel name things a little bit weird.
– 炸鱼薯条德里克
Dec 31 '18 at 7:15
man7.org/linux/man-pages/man5/proc.5.html It's just kernel name things a little bit weird.
– 炸鱼薯条德里克
Dec 31 '18 at 7:15
add a comment |
2 Answers
2
active
oldest
votes
When looking at /proc/$pid/status
, then the Tgid:
and Pid:
fields will always match, since they're the same for a process or for the main thread of a process.
The reason why there are two separate fields is that the same code is used to produce /proc/$pid/task/$tid/status
, in which Tgid:
and Pid:
may differ from each other. (More specifically, Tgid:
will match $pid
and Pid:
will match $tid
in the file name template used above.)
The naming is a bit confusing, mainly because threading support was only added to the Linux kernel later on and, at the time, the scheduler code was modified to reuse the logic that used to schedule processes so it would now schedule threads. This resulted in reusing the concept of "pids" to identify individual threads. So, in effect, from the kernel's point of view, "pid" is still used for threads and "tgid" was introduced for processes. But from userspace you still want the PID to identify a process, therefore userspace utilities such as ps
, etc. will map kernel's "tgid" to PID and kernel's "pid" to "tid" (thread id.)
add a comment |
TGid and Pid are different for threads spawned from the process leader.
eg looking at my polkitd
process:
% ps -Lp 2642
PID LWP TTY TIME CMD
2642 2642 ? 00:00:18 polkitd
2642 2680 ? 00:00:00 gmain
2642 2683 ? 00:00:30 gdbus
2642 2685 ? 00:00:00 polkitd
2642 2687 ? 00:00:00 JS GC Helper
2642 2688 ? 00:00:00 JS Sour~ Thread
2642 2692 ? 00:00:00 polkitd
If I look at process 2680
:
% egrep ^'(Tgid|Pid):' /proc/2680/status
Tgid: 2642
Pid: 2680
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f491691%2fare-tgid-and-pid-ever-different-for-a-process-or-lightweight-process%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
When looking at /proc/$pid/status
, then the Tgid:
and Pid:
fields will always match, since they're the same for a process or for the main thread of a process.
The reason why there are two separate fields is that the same code is used to produce /proc/$pid/task/$tid/status
, in which Tgid:
and Pid:
may differ from each other. (More specifically, Tgid:
will match $pid
and Pid:
will match $tid
in the file name template used above.)
The naming is a bit confusing, mainly because threading support was only added to the Linux kernel later on and, at the time, the scheduler code was modified to reuse the logic that used to schedule processes so it would now schedule threads. This resulted in reusing the concept of "pids" to identify individual threads. So, in effect, from the kernel's point of view, "pid" is still used for threads and "tgid" was introduced for processes. But from userspace you still want the PID to identify a process, therefore userspace utilities such as ps
, etc. will map kernel's "tgid" to PID and kernel's "pid" to "tid" (thread id.)
add a comment |
When looking at /proc/$pid/status
, then the Tgid:
and Pid:
fields will always match, since they're the same for a process or for the main thread of a process.
The reason why there are two separate fields is that the same code is used to produce /proc/$pid/task/$tid/status
, in which Tgid:
and Pid:
may differ from each other. (More specifically, Tgid:
will match $pid
and Pid:
will match $tid
in the file name template used above.)
The naming is a bit confusing, mainly because threading support was only added to the Linux kernel later on and, at the time, the scheduler code was modified to reuse the logic that used to schedule processes so it would now schedule threads. This resulted in reusing the concept of "pids" to identify individual threads. So, in effect, from the kernel's point of view, "pid" is still used for threads and "tgid" was introduced for processes. But from userspace you still want the PID to identify a process, therefore userspace utilities such as ps
, etc. will map kernel's "tgid" to PID and kernel's "pid" to "tid" (thread id.)
add a comment |
When looking at /proc/$pid/status
, then the Tgid:
and Pid:
fields will always match, since they're the same for a process or for the main thread of a process.
The reason why there are two separate fields is that the same code is used to produce /proc/$pid/task/$tid/status
, in which Tgid:
and Pid:
may differ from each other. (More specifically, Tgid:
will match $pid
and Pid:
will match $tid
in the file name template used above.)
The naming is a bit confusing, mainly because threading support was only added to the Linux kernel later on and, at the time, the scheduler code was modified to reuse the logic that used to schedule processes so it would now schedule threads. This resulted in reusing the concept of "pids" to identify individual threads. So, in effect, from the kernel's point of view, "pid" is still used for threads and "tgid" was introduced for processes. But from userspace you still want the PID to identify a process, therefore userspace utilities such as ps
, etc. will map kernel's "tgid" to PID and kernel's "pid" to "tid" (thread id.)
When looking at /proc/$pid/status
, then the Tgid:
and Pid:
fields will always match, since they're the same for a process or for the main thread of a process.
The reason why there are two separate fields is that the same code is used to produce /proc/$pid/task/$tid/status
, in which Tgid:
and Pid:
may differ from each other. (More specifically, Tgid:
will match $pid
and Pid:
will match $tid
in the file name template used above.)
The naming is a bit confusing, mainly because threading support was only added to the Linux kernel later on and, at the time, the scheduler code was modified to reuse the logic that used to schedule processes so it would now schedule threads. This resulted in reusing the concept of "pids" to identify individual threads. So, in effect, from the kernel's point of view, "pid" is still used for threads and "tgid" was introduced for processes. But from userspace you still want the PID to identify a process, therefore userspace utilities such as ps
, etc. will map kernel's "tgid" to PID and kernel's "pid" to "tid" (thread id.)
answered Dec 31 '18 at 7:30
filbrandenfilbranden
7,3702836
7,3702836
add a comment |
add a comment |
TGid and Pid are different for threads spawned from the process leader.
eg looking at my polkitd
process:
% ps -Lp 2642
PID LWP TTY TIME CMD
2642 2642 ? 00:00:18 polkitd
2642 2680 ? 00:00:00 gmain
2642 2683 ? 00:00:30 gdbus
2642 2685 ? 00:00:00 polkitd
2642 2687 ? 00:00:00 JS GC Helper
2642 2688 ? 00:00:00 JS Sour~ Thread
2642 2692 ? 00:00:00 polkitd
If I look at process 2680
:
% egrep ^'(Tgid|Pid):' /proc/2680/status
Tgid: 2642
Pid: 2680
add a comment |
TGid and Pid are different for threads spawned from the process leader.
eg looking at my polkitd
process:
% ps -Lp 2642
PID LWP TTY TIME CMD
2642 2642 ? 00:00:18 polkitd
2642 2680 ? 00:00:00 gmain
2642 2683 ? 00:00:30 gdbus
2642 2685 ? 00:00:00 polkitd
2642 2687 ? 00:00:00 JS GC Helper
2642 2688 ? 00:00:00 JS Sour~ Thread
2642 2692 ? 00:00:00 polkitd
If I look at process 2680
:
% egrep ^'(Tgid|Pid):' /proc/2680/status
Tgid: 2642
Pid: 2680
add a comment |
TGid and Pid are different for threads spawned from the process leader.
eg looking at my polkitd
process:
% ps -Lp 2642
PID LWP TTY TIME CMD
2642 2642 ? 00:00:18 polkitd
2642 2680 ? 00:00:00 gmain
2642 2683 ? 00:00:30 gdbus
2642 2685 ? 00:00:00 polkitd
2642 2687 ? 00:00:00 JS GC Helper
2642 2688 ? 00:00:00 JS Sour~ Thread
2642 2692 ? 00:00:00 polkitd
If I look at process 2680
:
% egrep ^'(Tgid|Pid):' /proc/2680/status
Tgid: 2642
Pid: 2680
TGid and Pid are different for threads spawned from the process leader.
eg looking at my polkitd
process:
% ps -Lp 2642
PID LWP TTY TIME CMD
2642 2642 ? 00:00:18 polkitd
2642 2680 ? 00:00:00 gmain
2642 2683 ? 00:00:30 gdbus
2642 2685 ? 00:00:00 polkitd
2642 2687 ? 00:00:00 JS GC Helper
2642 2688 ? 00:00:00 JS Sour~ Thread
2642 2692 ? 00:00:00 polkitd
If I look at process 2680
:
% egrep ^'(Tgid|Pid):' /proc/2680/status
Tgid: 2642
Pid: 2680
answered Dec 31 '18 at 13:36
Stephen HarrisStephen Harris
25.4k24477
25.4k24477
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f491691%2fare-tgid-and-pid-ever-different-for-a-process-or-lightweight-process%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
This has a good explanation when that can happen.
– std_unordered_map
Dec 31 '18 at 5:25
1
man7.org/linux/man-pages/man5/proc.5.html It's just kernel name things a little bit weird.
– 炸鱼薯条德里克
Dec 31 '18 at 7:15