开发者

Windows equivalent for Linux "screen" or another alternative?

I'm on the lookout 开发者_JS百科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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜