Solved

finding java process id using perl on Linux

Posted on 2007-11-18
4
2,119 Views
Last Modified: 2008-02-01
Whats the best way to find a java process for a particular user so that a system call for sighup can be issued? Basically I need to find the PID for several reasons - but the main one is it kill the jvm process from a tomcat installation. (There are more than one jvm running and  by having the user information I should be able to pull their active JAVA PID)

ps -u username | grep java works for bash.

In perl i tried:
system "ps -u username | grep java > tempPID.txt";

then i was going to access the file and pull the PID but I couldn't get the system call to work.

Any suggestions?

Thanks!
0
Comment
Question by:kipper3d
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 125 total points
ID: 20309895
Assuming your system has pgrep (most Unix/Linux systems do)

my $pid=`pgrep -U username java` or die "Can not run pgrep $!\n";
0
 
LVL 1

Author Comment

by:kipper3d
ID: 20310271
Wow! I had no idea there was such a thing. Beautiful. Thank you!
0
 
LVL 9

Expert Comment

by:Suhas .
ID: 20310287
on windows machine:

use module Win32::Process

1. $ProcessObj->GetProcessID()
2. Win32::Process::KillProcess($pid, $exitcode)
0
 
LVL 1

Author Comment

by:kipper3d
ID: 22003837
ok I tried this - finally.

The result:
5917 <- prints from Line 1
0 <- what is actually in $pid variable.

I need to carry the value 5917 in $pid to issue a kill statement but System returns 0
The statement above returns only a string.


my $pid = system("pgrep -U $user java");
 

print $pid;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now