In manpage of ps

tid         TID          the unique number representing a dispatchable
                         entity (alias lwp, spid).  This value may also
                         appear as: a process ID (pid); a process group
                         ID (pgrp); a session ID for the session leader
                         (sid); a thread group ID for the thread group
                         leader (tgid); and a tty process group ID for
                         the process group leader (tpgid).

   tgid        TGID      a number representing the thread group to which
                         a task belongs (alias pid).  It is the process
                         ID of the thread group leader.

In Ubuntu, tid and tgid seem always the same as pid, for both user processes, and kernel threads (I run ps -o pid,tid,tgid,cmd) Is it true in Linux, and why?

Is it true in other Unix such as System V or BSD?



You need to task ps to show thread information; otherwise it only lists processes:

ps -eL -o pid,tid,comm | awk '$1 != $2'

will show all the threads, apart from each process’ main thread, i.e. entries in the process table where pid and tid are different. The significant option is -L: without that, ps will only list entries where pid and tid are identical.

On FreeBSD, the equivalent option is -H. I haven’t checked other BSDs, or System V.

  • Hmm…this actually doesn't give an answer. Are they the same or not. – 炸鱼薯条德里克 Dec 29 '18 at 20:52
  • 1
    @炸鱼薯条德里克 awk '$1 != $2' should give a strong hint, but I’ve clarified that part. – Stephen Kitt Dec 29 '18 at 20:54
  • Thanks. "On FreeBSD, the equivalent option is -H". BSD style option doesn't have dash, does it? – Tim Dec 29 '18 at 21:45
  • 1
    @Tim: Linux ps doesn't use a dash, but the actual FreeBSD ps accepts both kinds (because it doesn't have to distinguish: all options in FreeBSD ps are "BSD style" options) and the manual page actually documents them with a dash. – user1686 Dec 29 '18 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.