Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

pthreads and waitpid

 
   Soft32 Home -> Linux2 Arch -> App Development RSS
Next:  variable sized structures.  
Author Message
Armel Asselin

External


Since: Feb 28, 2006
Posts: 23



(Msg. 1) Posted: Mon May 15, 2006 11:53 pm
Post subject: pthreads and waitpid
Archived from groups: comp>os>linux>development>apps (more info?)

Hello,

I'm in front of the following problem: i'd like to launch some process
(using fork+execve) from a thread created through pthread_create
I would then like to call waitpid function on the launched process to wait
for the end of the process. Unfortunately it always ends up with an ECHILD
error (the pid is OK).

the function that makes waitpid is executed in the main thread (the one
which called pthread_create not the one which forked)... is this the reason
why waitpid does not 'see' my child process?
BTW, executing the fork+execve directly in main thread then calling waitpid
in the parent side works.

how could I make my call work? do I have to call waitpid from the parent
process only?

Regards
Armel
Back to top
Login to vote
Michael Kerrisk

External


Since: Feb 11, 2004
Posts: 69



(Msg. 2) Posted: Wed May 17, 2006 9:35 am
Post subject: Re: pthreads and waitpid [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mon, 15 May 2006 23:53:44 +0200, "Armel Asselin"
wrote:

>Hello,
>
>I'm in front of the following problem: i'd like to launch some process
>(using fork+execve) from a thread created through pthread_create
>I would then like to call waitpid function on the launched process to wait
>for the end of the process. Unfortunately it always ends up with an ECHILD
>error (the pid is OK).
>
>the function that makes waitpid is executed in the main thread (the one
>which called pthread_create not the one which forked)... is this the reason
>why waitpid does not 'see' my child process?
>BTW, executing the fork+execve directly in main thread then calling waitpid
>in the parent side works.
>
>how could I make my call work? do I have to call waitpid from the parent
>process only?

What kernel version and glibc version are you using?

So you have a very simple program demonstrating the problem that you
could post?

Cheers,

Michael
Back to top
Login to vote
Armel Asselin

External


Since: Feb 28, 2006
Posts: 23



(Msg. 3) Posted: Wed May 17, 2006 1:59 pm
Post subject: Re: pthreads and waitpid [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

(got a problem when sending this email, sorry for the inconvenience if you
get it multiple times)

> What kernel version and glibc version are you using?
>
> So you have a very simple program demonstrating the problem that you
> could post?

I use:
Linux debian 2.4.27-2-686 #1 Mon May 16 17:03:22 JST 2005 i686 GNU/Linux
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x405c9000) (4.0.2-2)
libc.so.6 => /lib/libc.so.6 (0x40703000) (2.3.5.Cool

I do not have a small program to demonstrate unfortunately, I could manage
to make the stuff work:
the waitpid function works only if the child process was forked directly.

I found in the man page of waitpid some blurbs about __WCLONE / __WALL I
think that I just understood what to do of that:
I should call something like: waitpid(pid, &status, WNOHANG|__WALL), isn't
it?
I imagine however that this __WALL is not portable to other Unices... do you
have an idea of which #ifdef I should use to protect the use of such macros?

I just tried with __WALL but got no luck, is there something special to do
to use that? the call always returns -1 even though the child exists.

Regards
Armel
Back to top
Login to vote
Michael Kerrisk

External


Since: Feb 11, 2004
Posts: 69



(Msg. 4) Posted: Thu May 18, 2006 10:22 am
Post subject: Re: pthreads and waitpid [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wed, 17 May 2006 13:59:27 +0200, "Armel Asselin"
wrote:

>> What kernel version and glibc version are you using?
>>
>> So you have a very simple program demonstrating the problem that you
>> could post?
>
>I use:
>Linux debian 2.4.27-2-686 #1 Mon May 16 17:03:22 JST 2005 i686 GNU/Linux
>libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x405c9000) (4.0.2-2)
>libc.so.6 => /lib/libc.so.6 (0x40703000) (2.3.5.Cool

Okay -- since you are on a 2.4.x kerenel, then you will be using
LinuxThreads. Under this implementation, only the creating thread can
wait for a child created using fork() (this does not conform to
POSIX...).

The modern threading implementation, NPTL, fixes this probem. But
you'll need a 2.6 kernel.

>I do not have a small program to demonstrate unfortunately, I could manage
>to make the stuff work:
>the waitpid function works only if the child process was forked directly.
>
>I found in the man page of waitpid some blurbs about __WCLONE / __WALL I
>think that I just understood what to do of that:
>I should call something like: waitpid(pid, &status, WNOHANG|__WALL), isn't
>it?
>I imagine however that this __WALL is not portable to other Unices... do you
>have an idea of which #ifdef I should use to protect the use of such macros?
>
>I just tried with __WALL but got no luck, is there something special to do
>to use that? the call always returns -1 even though the child exists.

Sorry -- bottom line is that you need Linux 2.6.

Cheers,

Michael
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Bug#410692: pthreads break c++ compile - It seems to break any c++ compile. My C programs using pthreads compile fine. Current work around is just to uninstal...

Bug#418958: kaffe-pthreads doesn't really "provide" kaffe - Package: kaffe-pthreads Version: 2:1.1.7-4 Severity: important A package that build depends on kaffe to call something...

Bug#410692: pthreads break c++ compile (was: Bug#410692: l.. - hi, did you try the example? it is all pure C. please note that including pthread.h before stdlib.h builds with no..

need a live CD with sshd already loaded and a passworded a.. - I have a laptop with a broken display and the display broke before I could get the networking setup on it's Fedora core...

ssh on both sides - Hi, Im behind a firewall that allows certains outgoing connections but blocks incoming ones. As I can connect from wor...

slow upload with nfs over ssh tunnel - Hi, I have a problem with a terrible slow upload to the nfs server when the nfs protocol is passed through a ssh tunnel...
       Soft32 Home -> Linux2 Arch -> App Development All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
 Linux
 Mac
 PDA



[ Contact us | Terms of Service/Privacy Policy ]