[PATCH] tgid reported incorrectly in /proc/<pid>/status

Brian Inglis Brian.Inglis@SystematicSW.ab.ca
Sun Oct 18 20:52:36 GMT 2026


Hi folks,

Cygwin threads are dispatched on NT threads, as I see the expected thread count 
for cygserver under Task Mangler: 339 > 327 == 310 + 16 + 1 (main):

$ grep thread /etc/cygserver.conf
# kern.srv.cleanup_threads: No. of cygserver threads used for cleanup tasks.
# Default: 2, Min: 1, Max: 16, command line option -c, --cleanup-threads
#kern.srv.cleanup_threads 2
kern.srv.cleanup_threads 16
# kern.srv.request_threads: No. of cygserver threads used to serve
# Default: 10, Min: 1, Max: 310, command line option -r, --request-threads
#kern.srv.request_threads 10
kern.srv.request_threads 310

I referred the underlying issue to developers, because I know some have been 
working on dealing with with non-Cygwin process threads, and it would be good to 
see NT threads treated like Linux LWP Threads, and similar information made 
available about them under the hood.

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry


On 2026-10-18 12:36, ASSI via Cygwin-patches wrote:
> From b9f66fe5a55ac39f0bbbcfe9d96cade9927f672d Mon Sep 17 00:00:00 2001
> From: Achim Gratz <Stromeko@Stromeko.DE>
> Date: Sun, 18 Oct 2026 19:56:13 +0200
> Subject: [PATCH] winsup/cygwin/fhandler/process.cc: correct tgid value
> 
> Cygwin has historically (and incorrectly) reported the pgid as the
> tgid in /proc/<pid>/status even though LWP don't exist on Cygwin.
> Since the Threads parameter was missing at the time, this latent bug
> was lying dormant as that signifies an invalid tgid on Linux (the same
> as for a Threads parameter of zero).  However, commit 9756b33 changed
> that to reporting a number of threads in the Threads parameter that is
> totally unrelated to LWP, which triggered the bug: procps now reports
> the tgid instead of the pid as it does on Linux and expects that only
> the leader process (tgid==pid) should get reported unless you ask for
> all LWP to be shown.  This either suppresses the output for that
> process completely or shows the wrong PID for many processes.  Regain
> some sanity by ensuring tgid==pid for all Cygwin processes as LWP
> don't exist.
> 
> This patch does not change the reporting of parameter Threads (which
> should probably always be 0 on Cygwin to conform to the expectations
> set by Linux), however it is currently unknown if that deviation is
> actually causing problems in existing programs.  Any program using
> this number should expect the number of threads to change between
> reading this parameter and actually getting to the point where it
> could enumerate them.  However, seeing a Thread value different from
> zero might reasonably enable code paths that try to open directory
> /proc/<pid>/task (which contains all threads in that thread group on
> Linux).  Cygwin doesn't have this unless someone whips up an LWP
> emulation for it, so for that reason it might be better to revert to
> reporting zero.
> 
> Signed-off-by: Achim Gratz <Stromeko@Stromeko.DE>
> Reported-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
> ---
>   winsup/cygwin/fhandler/process.cc | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler/process.cc b/winsup/cygwin/fhandler/process.cc
> index 404668661..86ca05e5e 100644
> --- a/winsup/cygwin/fhandler/process.cc
> +++ b/winsup/cygwin/fhandler/process.cc
> @@ -1335,7 +1335,9 @@ format_process_status (void *data, char *&destbuf)
>   				   "SigIgn:\t%016lx\n",
>   			  cmd,
>   			  state, state_str,
> -			  p->pgid,
> +			  p->pid, /* this is the tgid on Linux, but
> +				     Cygwin doesn't have LWP -- treat
> +				     all processes as leaders */
>   			  p->pid,
>   			  p->ppid,
>   			  p->uid, p->uid, p->uid, p->uid,
> @@ -1343,7 +1345,11 @@ format_process_status (void *data, char *&destbuf)
>   			  vmsize * kb_per_page, 0UL, vmrss * kb_per_page,
>   			  vmdata * kb_per_page, 0UL, vmtext * kb_per_page,
>   			  vmlib * kb_per_page,
> -			  num_threads,
> +			  num_threads, /* should really be the number
> +					  of LWP in the same thread
> +					  group, not the number of NT
> +					  threads attached to this
> +					  process */
>   			  pnd, blk, ign
>   			  );
>   }



More information about the Cygwin-developers mailing list