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.
proper operation of exec() in multithreaded environment?
-
- Member
- Posts: 63
- Joined: Fri May 01, 2015 2:23 am
- Libera.chat IRC: Hellbender
Re: proper operation of exec() in multithreaded environment?
(The Open Group Base Specifications Issue 7)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 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.