gpt4 book ai didi

multithreading - 子流程是否与其父流程共享任何资源?

转载 作者:行者123 更新时间:2023-12-03 12:52:05 25 4
gpt4 key购买 nike

我阅读了以下内容,并想知道这是否可能或正确!

"Creating an application process (A) which execute and creating 1st thread to execute an application (application process (B)). A 2nd thread may be created within the application process (A) to execute the agent program(thread or process C). Therefore, the application process (B) and the agent (thread or process C) may share operating system allocated resources."



我的问题是:
  • 执行由进程A创建的进程B和线程 C,共享
    有什么资源吗?
  • 执行由进程A创建的进程B和进程 C,共享
    有什么资源吗?

  • 我认为一个进程的资源是隔离的,即使它们是由其他进程(父级)创建/执行的。
    如果我错了,我将很高兴从上面列出的用例中以及在哪种操作系统(Windows/iOS/Linux)中获得它们共享哪些资源,在哪种情况下。

    谢谢!

    最佳答案

    我对两个问题的原始回答是,但是在John发表评论之后,我要补充一点-由于父子进程之间如何共享文件描述符,两个兄弟进程最终可能会在彼此之间共享文件描述符。

    现在有人可以简单地向我解释文件描述符吗?是的,答案是here.

    父进程A可能与其子进程B和C共享文件描述符,因此B&C将共享文件描述符(不过由OS决定)。

    除此之外,线程C不会与进程B共享任何资源,因为该线程属于进程A,进程C也不会与从同一父级创建的另一个进程B共享任何资源。

    如果进程B和C共享任何内容,则仅与它们的父进程共享。对于某些B和C,无论它们是从同一父级创建的,还是与C是进程或线程一样,都不会共享任何东西。引用维基百科文章here:

    typically, the child process performs only a small set of actions before it ceases execution of its program in favour of the program to be started, and it requires very few, if any, of its parent's data structures.



    有多种方法可以实现进程间通信(aka IPC),可以从 here中看到。

    关于multithreading - 子流程是否与其父流程共享任何资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32169316/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com