Are tgid and pid ever different for a process or lightweight process?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















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.










share|improve this question
























  • 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















0















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.










share|improve this question
























  • 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













0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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










2 Answers
2






active

oldest

votes


















2














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.)






share|improve this answer






























    2














    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





    share|improve this answer






















      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
      );



      );













      draft saved

      draft discarded


















      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









      2














      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.)






      share|improve this answer



























        2














        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.)






        share|improve this answer

























          2












          2








          2







          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.)






          share|improve this answer













          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.)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 31 '18 at 7:30









          filbrandenfilbranden

          7,3702836




          7,3702836























              2














              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





              share|improve this answer



























                2














                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





                share|improve this answer

























                  2












                  2








                  2







                  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





                  share|improve this answer













                  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






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 31 '18 at 13:36









                  Stephen HarrisStephen Harris

                  25.4k24477




                  25.4k24477



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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






                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay