Originally posted by Lakshitha Ranasinghe:
If I can Identify the currently running processes (by Id or any other way)
On the Windows Platform the process ID is
not a reliable method of identifying processes. On unix it's "pretty" reliable as process IDs are used sequentially until rollover is necessary. On Windows new processes will reuse process IDs of recently deceased processes. In C/C++ or .NET you have to obtain the process handle and associate that with an unique external identifier like an User ID or Session ID to track the identity of the process in the program and to relate it to that external entity.
So basically hold on to the Java Process object that is created and assign it an identity that makes sense within your application and store that pair somewhere (e.g. Hashmap).
That being said, you can always use the
Tasklist command (from
java.lang.Runtime.exec() or
java.lang.ProcessBuilder) and parse (or regex match) its output looking for your image names (e.g. myProgram.exe) and the associated process IDs. However just because there was a "myProgram.exe 1396" 20 minutes ago, doesn't necessarily imply that the current "myProgram.exe 1396" is the same process instance. The one from 20 minutes ago may have died and a new "myProgram.exe" may have gotten its process ID.
[ March 29, 2006: Message edited by: Peer Reynders ]