调用exec()时,线程会发生什么情况? [英] What happens to threads when exec() is called?

查看:224
本文介绍了调用exec()时,线程会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上一门OS课,并试图解决这个问题,我们将不胜感激:

I am taking an OS class and trying to wrap my head around this question, any help would be appreciated:

如果一个进程中的多个线程之一进行exec()调用,那么其他线程会发生什么情况?为什么?

What happens to the other threads, if one of many threads within a process makes an exec() call? Why?

我对exec()的理解是用一个新进程替换了当前进程,它与fork()的主要区别在于fork()创建了一个克隆,最后得到了重复.

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()替换当前进程,它将杀死旧进程的线程并用新线程替换它们吗?任何帮助将不胜感激.

So if exec() replaces the current process, would it kill the threads of the old process and replace them with the new one? Any help will be appreciated.

推荐答案

在符合POSIX的类Unix系统上:

On POSIX-compliant Unix-like systems:

从具有多个线程的进程中调用任何exec函数将导致所有线程终止,并加载并执行新的可执行映像.不得调用析构函数或清除处理程序.

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*完成后,只有一个线程.

After exec* completes, there is just one thread.

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

(顺便说一句,我认为他们的意思是写对任何exec函数的成功调用...",因为文本对于不成功的调用没有意义.)

(Incidentally, I think they meant to write "A successful call to any exec function...", as the text makes no sense for unsuccessful calls.)

这篇关于调用exec()时,线程会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆