Windows equivalent for Linux “screen” or another alternative?

我是研究僧i 提交于 2019-12-03 10:58:45

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!