调用 exec() 时线程会发生什么情况?
What happens to threads when exec() is called?
我正在参加 OS class 并试图解决这个问题,我们将不胜感激:
What happens to the other threads, if one of many threads within a process makes an exec() call? Why?
我对 exec() 的理解是用一个新进程替换当前进程,它与 fork() 的主要区别在于 fork() 创建一个克隆,你最终得到重复项。
那么如果exec()替换当前进程,会不会kill掉旧进程的线程,换成新进程?任何帮助将不胜感激。
在 POSIX 兼容的类 Unix 系统上:
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. No destructor functions or cleanup handlers shall be called.
exec*
完成后,只有一个线程。
http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
(顺便说一下,我认为他们的意思是写 "A successful call to any exec function...",因为文本对于不成功的调用毫无意义。)
我正在参加 OS class 并试图解决这个问题,我们将不胜感激:
What happens to the other threads, if one of many threads within a process makes an exec() call? Why?
我对 exec() 的理解是用一个新进程替换当前进程,它与 fork() 的主要区别在于 fork() 创建一个克隆,你最终得到重复项。
那么如果exec()替换当前进程,会不会kill掉旧进程的线程,换成新进程?任何帮助将不胜感激。
在 POSIX 兼容的类 Unix 系统上:
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. No destructor functions or cleanup handlers shall be called.
exec*
完成后,只有一个线程。
http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
(顺便说一下,我认为他们的意思是写 "A successful call to any exec function...",因为文本对于不成功的调用毫无意义。)