Detect and communicate with a process by name?

BlitzMax Forums/BlitzMax Programming/Detect and communicate with a process by name?

JoshK(Posted 2006) [#1]
How would I detect whether a (windowless) process is running by the exe name, and what suggestions do you have for communicating with a running process? Reliability and compatibility on different systems are the most important issues here.


Picklesworth(Posted 2006) [#2]
I'm assuming this is with Windows? Or is it cross-platform?

Mutexes spring to mind for detecting processes.
For communication, there are a few solutions... one is stdin and stdout.

There is a nice table of methods that you can explore over at Wikipedia:
http://en.wikipedia.org/wiki/Inter-process_communication
It's not the be-all-end-all explanation, but it does provide some terminology which is always handy for further searching.

You probably aren't looking for the Linux ways, but I happen to have a very nice page bookmarked, so I may as well show it to you:
http://www.linuxhq.com/guides/LPG/node7.html
Lots of those methods are similar with Windows.


Brendane(Posted 2006) [#3]
On Windows systems you should use named pipes - there is no need to get a handle to the process in that case. One process acts as a server, the other processes connect to the named pipe using CreateFile() (windows treats named pipes like files).

Look up CreateNamedPipe() and ConnectNamedPipe() in msdn. These basically act similar to a windows socket where ConnectNamedPipe() is synonymous with Accept() to wait for connections. Easy to manage if you know only one process is going to connect to it, otherwise you need to manage each connection by creating a new thread for it (or write your code such that it is non-blocking and just calls poll routines for each connection).

If you really need to detect a windowless process, that is a different matter, since enumerating processes is different depending on the windows version, but if you stick to the named pipe method you can connect to the pipe and query the process handle via a message - et voila.