From owner-freebsd-hackers@freebsd.org Sun Aug 12 20:33:08 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 C060B107B74E for ; Sun, 12 Aug 2018 20:33:08 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from smtp.digiware.nl (smtp.digiware.nl [IPv6:2001:4cb8:90:ffff::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 58641781F5 for ; Sun, 12 Aug 2018 20:33:08 +0000 (UTC) (envelope-from wjw@digiware.nl) Received: from router.digiware.nl (localhost.digiware.nl [127.0.0.1]) by smtp.digiware.nl (Postfix) with ESMTP id 576027875A; Sun, 12 Aug 2018 22:33:06 +0200 (CEST) X-Virus-Scanned: amavisd-new at digiware.com Received: from smtp.digiware.nl ([127.0.0.1]) by router.digiware.nl (router.digiware.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U1wHCQ02fVI2; Sun, 12 Aug 2018 22:33:05 +0200 (CEST) Received: from [192.168.11.152] (unknown [192.168.11.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.digiware.nl (Postfix) with ESMTPSA id BAB5E78759 for ; Sun, 12 Aug 2018 22:33:05 +0200 (CEST) Subject: Write a version for pthread_get_name_np References: <7fa2b876-9397-da2b-cb29-56badf11b66d@ecoracks.nl> To: FreeBSD Hackers From: Willem Jan Withagen X-Forwarded-Message-Id: <7fa2b876-9397-da2b-cb29-56badf11b66d@ecoracks.nl> Message-ID: <42689feb-9bd4-429b-63d7-b9193123ee47@digiware.nl> Date: Sun, 12 Aug 2018 22:33:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <7fa2b876-9397-da2b-cb29-56badf11b66d@ecoracks.nl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Aug 2018 20:33:08 -0000 Hi, For some porting I'm trying to write a pthread_get_name_np(), but I have run into a snag.... Tried some the the procstat code I would come up with: int pthread_get_name_np(pthread_t *thread,                         char *name, size_t len){     struct procstat *procstat;     int pid = getpid();     unsigned int count, i;     struct kinfo_proc *kip, *kipp;     procstat = procstat_open_sysctl();     kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD,             pid, &count);     for (i = 0; i < count; i++) {         kipp = &kip[i];         printf("thread: %ld(0x%lx), %ld(0x%lx)\n", thread, thread, kipp->ki_tid, kipp->ki_tid);         if (thread == kipp->ki_tid) {             kinfo_proc_thread_name(kipp, name, len);         }     }     return 0; } Problem only is that the TID value in what procstat_getprocs returns in ki_tid is nowhere near what pthread_self() returns. But both manual page and the include file describe the value as Thread ID. Only in sys/user.h the type is     lwpid_t ki_tid;                 /* XXXKSE thread id */ What do I need to translate one tid into the other so I can really compare them? Thanx, --WjW