9

I'm using htop and looking at a process (rg) which launched multiple threads to search for text in files, here's the tree view in htop:

PID   Command
1019  |- rg 'search this'
1021     |- rg 'search this'
1022     |- rg 'search this'
1023     |- rg 'search this'

Why am I seeing PIDs for the process' threads? I thought threads didn't have a PID and they just shared their parent's PID.

AdminBee
  • 22,803
Dean
  • 424

1 Answers1

16

In Linux, each thread has a pid, and that’s what htop shows. The “process” to which all the threads belong is the thread whose pid matches its thread group id.

In your case, grep Tgid /proc/1021/status would show the value 1019 (and this would be true for all the rg identifiers shown by htop).

See Are threads implemented as processes on Linux? for details.

Stephen Kitt
  • 434,908