NetBSD Problem Report #46584

From www@NetBSD.org  Mon Jun 11 08:03:35 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 3659263B89C
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 11 Jun 2012 08:03:35 +0000 (UTC)
Message-Id: <20120611080334.1F90863B882@www.NetBSD.org>
Date: Mon, 11 Jun 2012 08:03:34 +0000 (UTC)
From: naruse@airemix.jp
Reply-To: naruse@airemix.jp
To: gnats-bugs@NetBSD.org
Subject: /proc/[pid]/task doesn't work 
X-Send-Pr-Version: www-1.0

>Number:         46584
>Category:       kern
>Synopsis:       /proc/[pid]/task doesn't work
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 11 08:05:00 +0000 2012
>Originator:     Yui NARUSE
>Release:        6.99.7
>Organization:
>Environment:
NetBSD kelvena.airemix.net 6.99.7 NetBSD 6.99.7 (GENERIC) #2: Thu May 17 14:42:34 JST 2012  naruse@kelvena.airemix.net:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
>Description:
Recently NetBSD-current has /proc/[pid]/task but attached program doesn't work.
It only show main thread, doesn't show sub threads.
It correctly works on at least Ubuntu 10.04 amd64.

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
void *dummy(void *p) {
    sleep(100);
    return NULL;
}
int main(void) {
    int i;
    DIR *dirp;
    struct dirent *dp;
    pthread_t *thread = malloc(sizeof(pthread_t));
    if (pthread_create(thread, NULL, dummy, &i)) {
        perror("pthread_create");
        abort();
    }

    dirp = opendir("/proc/self/task");
    while (dp = readdir(dirp)) {
        printf("%s\n", dp->d_name);
    }
    return 0;
}
>How-To-Repeat:
% cat proc.c
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
void *dummy(void *p) {
    sleep(100);
    return NULL;
}
int main(void) {
    int i;
    DIR *dirp;
    struct dirent *dp;
    pthread_t *thread = malloc(sizeof(pthread_t));
    if (pthread_create(thread, NULL, dummy, &i)) {
        perror("pthread_create");
        abort();
    }

    dirp = opendir("/proc/self/task");
    while (dp = readdir(dirp)) {
        printf("%s\n", dp->d_name);
    }
    return 0;
}
% cc -pthread proc.c&&./a.out
.
..
22667
>Fix:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.