Getting PIDs for system processes

S

skip

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
 
?

=?ISO-8859-1?Q?Daniel_Sj=F6blom?=

skip said:
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
 
S

skip

Daniel said:
skip said:
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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top