Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Getting PIDs for system processes

Thread view: 
skip - 22 Oct 2005 09:39 GMT
Does anybody know of a good way to determine the PID for a Linux system
process from within Java?

In other words, in my application I want to determine if mysql is
running. Should I do this by 'Runtime.getRuntime().exec()'? Is there a
better way?

TIA
Roedy Green - 22 Oct 2005 10:52 GMT
>In other words, in my application I want to determine if mysql is
>running. Should I do this by 'Runtime.getRuntime().exec()'? Is there a
>better way?

If you can do it in  C, a bit of JNI glue will get it much faster.

see http://mindprod.com/jgloss/jni.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Daniel Sjöblom - 22 Oct 2005 11:22 GMT
> Does anybody know of a good way to determine the PID for a Linux system
> process from within Java?
>
> In other words, in my application I want to determine if mysql is
> running. Should I do this by 'Runtime.getRuntime().exec()'? Is there a
> better way?

Parsing the output of e.g. ps or more conveniently pidof is probably the
easiest thing to do, but be sure to read the manpages of those commands
carefully before using the info to do anything potentially dangerous. If
you have something against that solution, you could scan the /proc file
system by hand, and examine e.g. /proc/[pid]/stat, /proc/[pid]/exe among
other things, but keep in mind that the output may change between kernel
versions, so this could/will be hard to maintain.

I also suggest you ask your question in a linux group, try
comp.os.linux.development.apps.

Daniel Sjöblom
skip - 23 Oct 2005 03:00 GMT
>>Does anybody know of a good way to determine the PID for a Linux system
>>process from within Java?
[quoted text clipped - 15 lines]
>
> Daniel Sjöblom

Parsing pidof works well and is (for me) the simplest option. Thank you.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.