vmwarejavasigar

Get process ID by part of its process name at Sigar


I'm using Sigar library to get the process ID and monitor it.

I have a process which can change of name depending on the version of the application which runs that process. For example:

Is there a way using Sigar to get the process Id by specifing something like myProcess% ?

Right now I'm using this:

ProcessFinder find = new ProcessFinder(this.sigar);
long[] pids = find.find("Exe.Name.ct=" + this.processName);

I've been trying to use regular expresions by using the PTQL (Process Table Query Language) syntax without success:

//getting the process with name "Photoshop.exe" (not working currently)
long[] pids = find.find("Exe.Name.re=^Photo(.)*.exe$);

Solution

  • Exe.Name returns the path to the running process, not just the name of the process.

    Therefore your regular expression should look like this:

    long[] pids = this.find.find("Exe.Name.re=^.*\\\\Photo(.)*.exe$");