proper operation of exec() in multithreaded environment?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

proper operation of exec() in multithreaded environment?

Post by mariuszp »

I am really confused about how exec() should operate in a multithreaded environment.

If we have threads A and B, which share memory and process ID, and thread A calls exec(), it now runs in a new address space, correct? But they still share the same process ID and so are still technically part of the same process.

Is this how it is supposed to be? I can see a lot of problems that may arise from a newly-started applications running alongside other threads with the same pid without knowing they exist.
Hellbender
Member
Member
Posts: 63
Joined: Fri May 01, 2015 2:23 am
Libera.chat IRC: Hellbender

Re: proper operation of exec() in multithreaded environment?

Post by Hellbender »

A call to any exec function from a process with more than one thread shall result in all threads being terminated and the new executable image being loaded and executed.
(The Open Group Base Specifications Issue 7)

The exec'ed process starts with a new thread. The new thread inherits bunch of stuff from the old one, but it is a new one. Technically it doesn't have to be new-new ("The thread ID of the initial thread in the new process image is unspecified."), but lots of stuff has to be reset, as described in the above link.
Hellbender OS at github.
Post Reply