Win32 进程如何获取其父进程的 pid? [英] How can a Win32 process get the pid of its parent?

查看:68
本文介绍了Win32 进程如何获取其父进程的 pid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将命令行上的 pid 传递给孩子,但是有没有办法在 Win32 API 中做到这一点?或者,如果父进程死了,有人可以减轻我的恐惧,即我传递的 pid 可能在一段时间后属于另一个进程吗?

I'm currently passing the pid on the command line to the child, but is there a way to do this in the Win32 API? Alternatively, can someone alleviate my fear that the pid I'm passing might belong to another process after some time if the parent has died?

推荐答案

请注意,如果父进程终止,则很有可能甚至可能会将该 PID 重用于另一个进程.这是标准的 Windows 操作.

Notice that if the parent process terminates it is very possible and even likely that the PID will be reused for another process. This is standard windows operation.

所以可以肯定的是,一旦您收到父级的 id 并确定它确实是您的父级,您应该打开它的句柄并使用它.

So to be sure, once you receive the id of the parent and are sure it is really your parent you should open a handle to it and use that.

这篇关于Win32 进程如何获取其父进程的 pid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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