Avatar of cspm2003
cspm2003

asked on 

get pid of a running java application

Hello,

I have the following problem: I have to get the pid of a running java application. the problem is that I do not directly start the java app, instead I run a bat or exe file which does some other stuff and in the end runs the java app.
In task manager it just shows up as java.exe but there are multiple java applications running on the server and I must find out which one to shut down.
The application opens tcp port 5555. I tryed to use netstat -o which works, but it is too slow! There are many open ports on the server and the netstat takes > 1 minute.
A nother way I could think of was to edit the batch file so that it gets the the pid of the java app when it is started and writes it to a file but II dont know how to get the pid within a batch file.

The server is running server2k3 if that helps any.

thx a ton in advance!
Windows OSMicrosoft Legacy OSWindows Server 2003

Avatar of undefined
Last Comment
Computer101
Avatar of grenade
grenade
Flag of India image

You may download a utility called processexplorer from sysinternals.
this utility tracks all the handles and DLLs which are operating at the moment, along with the respective PID assigned for a specific process or thread.
Using this you can check for Java.exe and it will list all the handles using it, based on the java app using it.
For further queries, get back to me.
Avatar of cspm2003
cspm2003

ASKER

can processexplorer be called from the command line? I need to programatically terminate the java application
Avatar of grenade
grenade
Flag of India image

i am not sure about a command line utility. its a GUI based program, to provide you info about the running processes. you can probably use it to find out the process and then kill it from task manager or command line, or use a program to terminate the application.
ASKER CERTIFIED SOLUTION
Avatar of b0fh
b0fh
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of cspm2003
cspm2003

ASKER

I looked into both tools, process explorer cant be called from the command line, and I dunno how I should determine which process to kill using pslist nor pskill.
Avatar of b0fh
b0fh
Flag of United States of America image

Have you checked the pstools.chm file for help?  You need to use the -t switch with pslist in order to show the tree for each process.  Then, you should be able to see the thread that needs to be killed.  It should look fairly similar to what you are able to see in process explorer.  

As long as the java process that needs to be killed is always running the same thread (and other java processes are not), then you may be able to kill that thread directly using pskill.

Does your original .exe or .bat wait for the java process to return control to it before terminating?  Depending upon how the java process was spawned, you may be able to use "pskill -t" to kill your original application and anything that it spawned as a descendant.

If this doesn't work, we'll have to look elsewhere for an answer.
SOLUTION
Avatar of RePC
RePC

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Computer101
Computer101
Flag of United States of America image

Forced accept.

Computer101
EE Admin
Windows Server 2003
Windows Server 2003

Windows Server 2003 was based on Windows XP and was released in four editions: Web, Standard, Enterprise and Datacenter. It also had derivative versions for clusters, storage and Microsoft’s Small Business Server. Important upgrades included integrating Internet Information Services (IIS), improvements to Active Directory (AD) and Group Policy (GP), and the migration to Automated System Recovery (ASR).

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo