简体   繁体   中英

Random Process ID is coming when executing WMIC command

I have more than one instance of java on the same machine one for Jenkins and other for the running server. Is there any way I can get the process id of the instance which is running the server?

I tried to use below command on command line -

WMIC PROCESS WHERE (CommandLine like '%cq-author-p4502%') GET ProcessID

Which returned >>

ProcessId 6100

And all the time I execute above command it returns the different ID even if the server is not running. And when the server is running, then that java server instance PID along with this randomly changing PID is returned. I am wondering why is this random PID is returned?

Any help is much appreciated!

The observed random PID is the one that is assigned to the wmic command you are running. If you only include a like operand over the CommandLine property, both the server (if it is running) and the wmic will match the condition as both commands include the same substring in their command lines.

You should include another condition so the wmic is not included, something like

wmic process where "CommandLine like '%cq-author-p4502%' and name='java.exe'" get ProcessID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM