Willem Jan Withagen
2018-08-12 20:33:06 UTC
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
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