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.

0

1 Answer 1

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .