且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取创建进程的线程所有者

更新时间:2023-02-21 07:40:58

我几乎确定这是不可能的,但也许不是100%肯定.线程之间的父子关系不会记录在系统中的任何位置,因此有关线程启动新进程的信息应该不可用.
请参阅以下讨论:
http: //***.com/questions/5142791/how-do-i-get-to-the-parent-thread-from-a-child-thread-or-another-thread [获取父流程PID [
I''m almost sure this is impossible, but maybe not 100% sure. The parent-child relationships between threads are not recorded anywhere in the system, so information on the thread started a new process should not be available.
Please see this discussion:
http://***.com/questions/5142791/how-do-i-get-to-the-parent-thread-from-a-child-thread-or-another-thread[^].
(Yes, I can see the discussed problem is different, I only suggest you consider different facts and infer the conclusion.)

At the same time, and ID of a parent process can be found (it this process still exists):
Get Parent Process PID[^].

If you really need it (please explain why), you can possibly work around the problem by passing the information of the thread to a child process using any suitable mechanism (even a command line). If you do this, be careful with a thread ID; remember that a thread could be terminated, be in one or another state at the moment you might use this ID. Actually, the whole idea of using this ID in an external process is quite concerned. I doubt that you can do anything useful with it. Again, I would be interested to know what''s your idea.

—SA