返回进程ID

发布于 2024-07-15 02:52:53 字数 304 浏览 5 评论 0原文

我有这个问题想要解决。 假设我们有这种情况。 我们有一个 notepad.exe 实例正在运行。 我运行另一个 notepad.exe。 现在我想杀死后者。 我该怎么做?

如果我能够知道最后一个 notepad.exe 的 pid,那么我就可以杀死它。 但是如何获取最后打开的程序的PID呢?

另一种方法是为每个应用程序指定一个唯一的映像名称。 据我所知,这似乎不可能,因为图像名称被硬编码到二进制文件中。

那么有什么想法吗?

PS 正如您已经注意到的,这一切都在 Windows 中。

I have this issue that I want to resolve. Lets think we have this situation. We have one instance of notepad.exe running. I run another notepad.exe. Now I want to kill the latter. How can I do it?

If I was able to know the pid of last notepad.exe then I could kill it. But how to get the PID of last opened program?

Another way is to give every application a unique image name. From what I learned it seems impossible becouse image names are hard coded into the binary file.

So any ideas?

P.S. As you already noticed this is all in windows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山人契 2024-07-22 02:52:53

如果这些是其他人的进程(即您自己没有启动它们),则 Windows 会跟踪 进程启动时(或其“创建时间"),所以我希望您可以使用该信息找到最后启动的进程。

If these are someone else's processes (i.e. you didn't start them yourself), then Windows keeps track of when the process was started (or its "creation time"), so I expect you could just find whichever process started last using that information.

动次打次papapa 2024-07-22 02:52:53

那么,您如何启动该流程? 例如,如果您从 C# 启动它,则静态 Process.Start 方法将返回一个 Process 实例,该实例具有一个 Id 和一个Kill() 方法。 该机制在架构/语言之间会有所不同......

如果您不通过代码来完成它,它可能是偏离主题的;-p

Well, how are you launching the process? For example, if you are launching it from C#, the static Process.Start method returns a Process instance, which has an Id, and a Kill() method. The mechanism will differ between architectures/languages...

And if you aren't doing it through code, it may be off-topic ;-p

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文