Windows 相当于 Linux 的“屏幕”或者另一种选择?

发布于 2024-10-18 07:48:00 字数 455 浏览 2 评论 0原文

我正在寻找一种在 Windows 环境中控制程序的方法。

我希望它有点类似于 Linux 软件“screen”。

我搜索的原因是我需要使用标识符启动一个程序(在 Windows 上),这样我以后就能够关闭该特定程序,而无需关闭其他任何程序 - 即使实际程序(.exe 文件)正在运行多次。那么我可以“命名”它吗?

我现在在 Linux 上使用以下程序:

$ screen <params> <id> ./softwareprogram

然后我知道我总是可以通过它的 ID 找到它:)

这是一个正在关闭或启动第 3 方程序的外部程序。

我的程序是用 C++ 编写的,如果这有什么区别的话。

编辑:我不能自己选择 ID 吗?喜欢用特定的名称启动程序吗?另外,如何通过提供名称来终止进程?

I'm on the lookout for a method to control programs in a Windows environment.

I would prefer it to be a bit similar to the Linux software "screen".

The reason of my search is that I need to start a program (on Windows) with an identifier, so I later would be able to close that specific program, without closing anything else - even though the actual program (.exe file) is running multiple times. So is there anyway I can "name" it?

I'm using the following on Linux now:

$ screen <params> <id> ./softwareprogram

And then I know I can always find it with it's ID :)

It's an external program which is closing or starting a 3rd party program.

My program is written in C++, if that does any difference.

Edit: Can't I by any means not choose the ID myself? Like start the program with a specific name? Also how do I kill the process by providing a name?

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

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

发布评论

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

评论(3

听风念你 2024-10-25 07:48:00

目前,我不相信屏幕有一个原生的等价物。 Cygwin 包含 screen 的实现,但它带来了 cygwin 的开销。问题在于 Windows 和基于 Posix 的操作系统以非常不同的方式实现控制台。 Windows 不支持 POSIX 环境中的许多 tty 功能。也就是说,可以使用 API 调用在屏幕实用程序中编写功能的最小实现:AttachConsoleFreeConsole。然而,我必须对这个主题做更多的研究。

At the moment, I don't believe there's a native equivalent for screen. Cygwin contains an implementation of screen, but it comes with the overhead of cygwin. The problem is that Windows and Posix-based operating systems implement consoles in a very different way. Windows does not support many of the tty functionality that is part of the POSIX environment. That being said, it may be possible to write a minimal implementation of the functionality in the screen utility using the API calls: AttachConsole and FreeConsole. I'd have to do a bit more research on the subject, however.

妳是的陽光 2024-10-25 07:48:00

当您启动程序时,即使在 Windows 上,您也可以获得其进程 ID。
您稍后可以使用该进程 ID 再次终止该程序。

如果您需要给它您自己的 id,那么您可以使用例如注册表来存储您的 id 到进程 id 的映射。如果收到启动命令,请将标识符作为键存储在注册表中,并将已启动进程的 pid 作为值存储。如果收到停止命令,请从注册表中检索 pid,并终止该 pid 并从注册表中删除该密钥。

当然,您也可以使用数据库或包含文件的文件夹来代替注册表,其中密钥(您的标识符)是文件名,而 pid 位于每个文件内

When you start the program, you can get its process id, even on windows.
You can later use that process id to kill the program again.

If you need to give it your own id, then you can use e.g. the registry to store a mapping of your id to process id. If you receive a start command, store the identifier in the registry as key and the pid of the started process as value. If you receive a stop command, retrieve the pid from the registry and kill that pid and delete the key from the registry.

Instead of the registry you could of course also use a database or a folder with files where the key (your identifier) is the filename and the pid is inside each file

生来就爱笑 2024-10-25 07:48:00

虽然我不知道 linux screen 命令的作用,但为什么不直接使用从 CreateProcess 获得的进程句柄呢?

您也可以获得进程 ID,但只有当该进程有打开的句柄时它才有效。

lpProcessInformation 参数将包含进程 ID 和进程句柄。

While I have no clue what the linux screen command does, why don't you just use the process-handle you get from CreateProcess?

You get the process-id too, but its only valid as long as there are open handles to that process.

The lpProcessInformation parameter will contain both the process-id and the process-handle.

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