From owner-freebsd-hackers@freebsd.org Wed May 2 09:08:56 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7765EFC6D71 for ; Wed, 2 May 2018 09:08:56 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.netplex.net", Issuer "RapidSSL RSA CA 2018" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0DEE57E21D; Wed, 2 May 2018 09:08:55 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from [10.0.0.52] (ip-414b102e.ct.fixed.ntplx.com [65.75.16.46]) (authenticated bits=0) by mail.netplex.net (8.15.1/8.15.1/NETPLEX) with ESMTPSA id w4293PXg042126 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 2 May 2018 05:03:25 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.netplex.net [204.213.176.9]); Wed, 02 May 2018 05:03:26 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) Subject: Re: Getting pthread names From: Daniel Eischen X-Mailer: iPhone Mail (15E302) In-Reply-To: <44e3f0c6-0397-404b-3fb9-a67e7f592024@freebsd.org> Date: Wed, 2 May 2018 05:03:25 -0400 Cc: Konstantin Belousov , Manuel St?hn , freebsd-hackers@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20180430111434.GA18085@freebsd-t450.fritz.box> <20180430135711.GT6887@kib.kiev.ua> <44e3f0c6-0397-404b-3fb9-a67e7f592024@freebsd.org> To: Julian Elischer X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 May 2018 09:08:56 -0000 > On May 1, 2018, at 10:38 PM, Julian Elischer wrote: >=20 >> On 30/4/18 9:57 pm, Konstantin Belousov wrote: >>> On Mon, Apr 30, 2018 at 01:14:34PM +0200, Manuel St?hn wrote: >>> Hi, >>>=20 >>> for setting a name for pthreads i found pthread_set_name_np(3), but for >>> retrieving the name i found nothing. Is there any api like >>> pthread_getname_np for FreeBSD? Or is there another way to retrieve the >>> threads name within an application? >> Not like pthread_getname_np(), but still something. You can use >> (binary) sysctl kern.proc.pid. to get struct kinfo_proc for all >> threads. In the structure, the ki_tdname() member contains the thread >> name as set by pthread_set_name_np(3). >> _______________________________________________ >> freebsd-hackers@freebsd.org mailing list >> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers >> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org= " >>=20 > and ps in the kernel debugger shows it as well from memory >=20 > check top and ps in "show thread" mode.... at one stage I remember writing= code to show thread names >=20 > but I can't remember what programs it went into.. (around 2001), >=20 >=20 > I suspect that you are expected to remember your own name. the name writin= g is so other processes can get that information. I think I toyed with idea of adding pthread_set_name_np() back in the old li= bc_r days. I'm not sure why I didn't? The problem with remembering to what you set each thread's name, is that the names may be set by libraries o= r code out of your control. Maybe not a common use case, though. The set n= ame function is void return, so you can't even get the name to see if the se= tter actually worked. I think the libc_r version just did a strdup() of sor= ts, so it could be as long as necessary (bug or feature?). The current lim= it seems to be MAXCOMLEN, which is 19, and I think just silently fails if mo= re than that. -- DE=