pthread+exec question

Eyal Lebedinsky eyal at eyal.emu.id.au
Sun Feb 10 21:02:43 EST 2002


Andreas Bauer wrote:
> 
> On Sun, Feb 10, 2002 at 11:41:27AM +1100, Eyal Lebedinsky wrote:
> > I am trying to undersnatd the interaction between threads and
> > exec(). The attached program demonstrates how the exec() behaves
> > differently when issued from inside a thread (./p) or directly
> > from main (./p x). In the former case the shell proceeds when
> > the exec is issued rather than wait for the completion of the
> > program.
> >
> > The problem is that the exec'ed program takes over the pid of
> > the thread rather than of main(), and the original process
> > exits, letting my shell proceed rather than wait.
> 
> If I recall correctly, that's a limitation of pthreads under Linux.

Not really just Linux. I had the pleasure under HP/UX too. I think it
is more of a basic issue. POSIX seems to say that the thread issuing
the exec() is the one that continues, but POSIX says nothing about
the relationship between processes and threads re pid. So doing the
exec() inside a thread may terminate the original pid (as it does
here) or may not (if all threads share a pid and are really
lightweight).

I think Solaris has the problem too, but I do need to recheck.

> See if you can buy or borrow Butenhof's "Programming with POSIX Threads".
> It's a nice introduction to pthreads.

Got it. Read it.

--
Eyal Lebedinsky (eyal at eyal.emu.id.au) <http://samba.org/eyal/>




More information about the linux mailing list