简体   繁体   English

调用 exec() 时线程会发生什么?

[英]What happens to threads when exec() is called?

I am taking an OS class and trying to wrap my head around this question, any help would be appreciated:我正在参加操作系统课程并试图解决这个问题,任何帮助将不胜感激:

What happens to the other threads, if one of many threads within a process makes an exec() call?如果进程中的多个线程之一进行 exec() 调用,其他线程会发生什么情况? Why?为什么?

My understanding of exec() is that is replaces the current process with a new one, and it's main difference from fork() is that fork() creates a clone and you end up with duplicates.我对 exec() 的理解是用新进程替换当前进程,它与 fork() 的主要区别在于 fork() 创建一个克隆,最终得到重复。

So if exec() replaces the current process, would it kill the threads of the old process and replace them with the new one?那么如果 exec() 替换当前进程,它会杀死旧进程的线程并用新进程替换它们吗? Any help will be appreciated.任何帮助将不胜感激。

On POSIX-compliant Unix-like systems:在兼容 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.从具有多个线程的进程调用任何 exec 函数将导致所有线程被终止,并加载和执行新的可执行映像。 No destructor functions or cleanup handlers shall be called.不得调用析构函数或清理处理程序。

After exec* completes, there is just one thread. exec*完成后,只有一个线程。

http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html

(Incidentally, I think they meant to write "A successful call to any exec function...", as the text makes no sense for unsuccessful calls.) (顺便说一句,我认为他们的意思是写“对任何 exec 函数的成功调用...”,因为该文本对于不成功的调用没有意义。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用 exec() 时线程会发生什么情况? - What happens to threads when exec() is called? 没有.join()时,python中的线程会发生什么? - What happens to threads in python when there is no .join()? Android-活动结束后线程会怎样? - Android - What happens to Threads when a Activity finishes? 当以下情况发生时-A.从可运行的B中调用Activity方法。多个线程同时调用Activity方法 - What happens when- A. Activity method is called from Runnable B. Multiple threads call Activity method simultaneously 丢失线程会发生什么? - What happens to lost threads? 当计时器线程没有按时完成时会发生什么 - What happens when timer threads don't finish on time 当少数线程尝试调用相同的同步方法时会发生什么? - What happens when few threads trying to call the same synchronized method? 释放锁定后,监视器的“条目”集中的线程会怎样? - What happens to threads in the Entry set of a monitor when the lock is released? Play Framework:当请求超出可用线程时会发生什么 - Play Framework: What happens when requests exceeds the available threads 当IntentService完成时,IntentService产生的线程会怎样? - What happens with threads spawned by an IntentService when IntentService finishes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM