[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#233589: marked as done (waitpid fails to wait for termination of a process started from a different thread )



Your message dated Thu, 21 Oct 2004 13:14:33 +0900
with message-id <81brewyafq.wl@omega.webmasters.gr.jp>
and subject line Bug#233589: waitpid fails to wait for termination of a process started from a different thread
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 18 Feb 2004 22:05:36 +0000
>From cris.sinnott@sand.com Wed Feb 18 14:05:36 2004
Return-path: <cris.sinnott@sand.com>
Received: from (sand.com) [66.46.70.5] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1AtZp1-0002ct-00; Wed, 18 Feb 2004 14:05:35 -0800
Received: from crisnt (DMZ.sandmtl.com [66.46.70.3])
	by sand.com (8.11.7/8.11.7) with SMTP id i1IM5Im12684
	for <submit@bugs.debian.org>; Wed, 18 Feb 2004 17:05:18 -0500
From: "Cris Sinnott" <cris.sinnott@sand.com>
To: <submit@bugs.debian.org>
Subject: waitpid fails to wait for termination of a process started from a different thread 
Date: Wed, 18 Feb 2004 17:00:08 -0500
Message-ID: <AIECKAIILFBAFLCIBODECENHDCAA.cris.sinnott@sand.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Importance: Normal
Delivered-To: submit@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_02_18 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-5.0 required=4.0 tests=HAS_PACKAGE autolearn=no 
	version=2.60-bugs.debian.org_2004_02_18
X-Spam-Level: 

Package:glibc
Version:2.3.2-90

Waitpid fails with errno 10 when called from a thread other than the one
that started the process being waited on. This happens regardless of whether
the threads were created with pthread_create() or clone() (see sample code).

The man pages installed on my system (see uname -a below), indicate that
libpthread/glibc support this behavior. From the LINUX NOTES section of the
man page for waitpid(2):

... since Linux 2.4  a thread can, and by default will, wait on children of
other threads in the same thread group...

my system
>uname -a
Linux amd64 2.4.21-193-smp #1 SMP Thu Jan 22 16:52:24 UTC 2004 x86_64 x86_64
x86_64 GNU/Linux

The sample code below demonstrates this problem.

<snippet>

#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <pthread.h>

static pthread_t processThreadId= 0;
extern char **environ;
#define STACKSIZE (1024 * 64)

#define USE_CLONE_FOR_THREADS 1
#define CLONE_FLAGS CLONE_PARENT | CLONE_THREAD | CLONE_FS | CLONE_FILES |
CLONE_SIGHAND | CLONE_VM

#if USE_CLONE_FOR_THREADS
int my_pthread_create( pthread_t *pthread, pthread_attr_t * attr, void
*(start_routine)(void *), void *arg)
{
   void *stack = (void *)(long)malloc ((size_t)STACKSIZE);
   fprintf(stderr, "my_pthread_create::Using clone\n" );
   *pthread = (pthread_t)clone( (int(*)(void *))start_routine, (char *)stack
+ STACKSIZE, CLONE_FLAGS, arg );
   return (*pthread>0?0:-1);
}
#else
#define my_pthread_create pthread_create
#endif

int my_system (const char *command)
{
    int pid, status;
    void *stack = malloc( 1024 * 64 );

    if (command == 0)
        return 1;
    fprintf(stderr,"my_system::Using fork\n");
    pid = fork();

    if (pid == -1)
        return -1;

    if (pid == 0) {
        char *argv[4];
        argv[0] = "sh";
        argv[1] = "-c";
        argv[2] = (char *)command;
        argv[3] = 0;
        fprintf(stderr,"my_system::Chaining\n");
        execve("/bin/sh", argv, environ);
        fprintf(stderr,"my_system::Chaining failed!\n");
        exit(127);
    }
    return pid;
}

void *WaitThread(void *arg)
{
    int pid     = *(int *)arg;
    int rpid    = 0;
    int status  = 0;

    fprintf(stderr, "WaitThread::Start\n");
    while(1)
    {
        fprintf(stderr,"WaitThread::Waiting on pid: %d\n",pid);
        rpid = waitpid(pid, &status, __WCLONE );
        if (rpid == -1)
        {
            fprintf(stderr,"WaitThread::Wait failed errno: %d\n",errno);
            if (errno != EINTR)
                break;
        }
        else
        {
            printf("WaitThread::success child status: %d\n",status);
            break;
        }
    }
    fprintf(stderr, "WaitThread::End\n");
    return (void *)(long)rpid;
}

void *ProcessThread(void *arg)
{
    int pid = 0;
    pthread_t waitThreadId;

    fprintf(stderr,"ProcessThread::Start\n");
    pid = my_system("/bin/sleep 100");

    if (pid == -1 )
    {
        fprintf(stderr, "ProcessThread::my_system failed errno : %d\n",
errno);
        exit(pid);
    }
    else
    {
        fprintf(stderr, "ProcessThread::Child pid = %d\n", pid);
    }
    my_pthread_create(&waitThreadId, 0, WaitThread, (void *)&pid);
    fprintf(stderr,"ProcessThread::End\n");
    return 0;
}

int main()
{
    fprintf(stderr,"Main::Start\n");

    my_pthread_create(&processThreadId, 0, ProcessThread, 0);

    sleep(1);
    fprintf(stdout,"<Press return to end>");
    fflush(stdout);
    getchar();

    fprintf(stderr,"Main::End\n");
    return 0;
}

</snippet>

Here is the output of this program when using the clone() system call to
create threads, the behavior is the same when using pthread_create():

Main::Start
my_pthread_create::Using clone
ProcessThread::Start
my_system::Using fork
my_system::Chaining
ProcessThread::Child pid = 8678
my_pthread_create::Using clone
WaitThread::Start
WaitThread::Waiting on pid: 8678
WaitThread::Wait failed errno: 10
WaitThread::End
ProcessThread::End
<Press return to end>
Main::End

Thanks in advance for any feedback on this.

Cris.


---------------------------------------
Received: (at 233589-done) by bugs.debian.org; 21 Oct 2004 04:14:33 +0000
>From gotom@debian.or.jp Wed Oct 20 21:14:33 2004
Return-path: <gotom@debian.or.jp>
Received: from omega.webmasters.gr.jp (webmasters.gr.jp) [218.44.239.78] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1CKULR-0001d1-00; Wed, 20 Oct 2004 21:14:33 -0700
Received: from omega.webmasters.gr.jp (localhost [127.0.0.1])
	by webmasters.gr.jp (Postfix) with ESMTP
	id 1E7B5DECC8; Thu, 21 Oct 2004 13:14:33 +0900 (JST)
Date: Thu, 21 Oct 2004 13:14:33 +0900
Message-ID: <81brewyafq.wl@omega.webmasters.gr.jp>
From: GOTO Masanori <gotom@debian.or.jp>
To: Daniel Jacobowitz <dan@debian.org>, 233589-done@bugs.debian.org
Cc: Cris Sinnott <cris.sinnott@sand.com>
Subject: Re: Bug#233589: waitpid fails to wait for termination of a process started from a different thread
In-Reply-To: <20040218222709.GA19959@nevyn.them.org>
References: <AIECKAIILFBAFLCIBODECENHDCAA.cris.sinnott@sand.com>
	<20040218222709.GA19959@nevyn.them.org>
User-Agent: Wanderlust/2.9.9 (Unchained Melody) SEMI/1.14.3 (Ushinoya)
 FLIM/1.14.3 (=?ISO-8859-4?Q?Unebigory=F2mae?=) APEL/10.3 Emacs/21.2
 (i386-debian-linux-gnu) MULE/5.0 (SAKAKI)
MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya")
Content-Type: text/plain; charset=US-ASCII
Delivered-To: 233589-done@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-6.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER 
	autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

At Wed, 18 Feb 2004 17:27:09 -0500,
Daniel Jacobowitz wrote:
> You have misinterpreted the man page.  In fact, LinuxThreads threads
> are not all in the same "thread group".  This will work using NPTL and
> a 2.6 kernel, but not otherwise.

I close this bug.  If you still have trouble, please let us know.

Regards,
-- gotom



Reply to: