Re: BUG: NTPL: waitpid() doesn't return?

From: bert hubert
Date: Sat Jan 31 2004 - 14:20:22 EST


[Added Ingo & NPTL list]

[Matthias reports that threads forking multiple programs and running waitpid
on them has problems]

On Sat, Jan 31, 2004 at 07:15:19PM +0100, Matthias Urlichs wrote:

> > If they do not wait for a specific pid, the kernel is right. The kernel has
> > no way of knowing which process a specific waitpid is waiting for otherwise!
> >
> Please check my original mail again. The thread _is_ waiting for a
> specific pid.

I can't reproduce this with 2.6.1, can you check if this works as intended
on your system? Should output:

Thread 0 Launched pid 10967
Thread 1 Launched pid 10971
Thread 1 waitpid for 10971 returned for 10971, status: 1
Thread 0 waitpid for 10967 returned for 10967, status: 3

This is with NPTL 0.60 (Debian Unstable).

./sleep program:

#!/bin/sh
sleep $1
exit $1

testcase.c:

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>

void unixDie(const char* what)
{
perror(what);
exit(1);
}
int s_counter;
void *func(void *p)
{
pid_t pid;
int status;
int counter=s_counter++;

pid=fork();
if(pid<0)
unixDie("doing fork");
if(!pid) {
char *arguments[]={"./sleep","",0};
char str[10];
sprintf(str,"%d",(int)p);
arguments[1]=str;

if(execve(arguments[0],arguments,0))
unixDie("doing execve");
}
if(pid) {
pid_t ret;
printf("Thread %d Launched pid %d\n", counter, pid);
ret=waitpid(pid, &status, 0);
if(ret<0)
unixDie("waitpid");

printf("Thread %d waitpid for %d returned for %d, status: %d\n",counter, pid, ret, WEXITSTATUS(status));
}

return 0;
}


int main(int argc, char **argv)
{
pthread_t t1, t2;
pthread_create(&t1, 0, func,(void*)3);
sleep(1);
pthread_create(&t2, 0, func,(void*)1);

pthread_join(t2,0);
pthread_join(t1,0);
return 0;
}


--
http://www.PowerDNS.com Open source, database driven DNS Software
http://lartc.org Linux Advanced Routing & Traffic Control HOWTO
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/