dcsimg
Pid process
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, September 18, 2002 12:52 AM

How I get the pid of a process in java?
I have to verify if the process that I'm going to run is still running and I think the best way is to keep this pid in a file. How I get it?
Thanks.

Re: Pid process

Posted By:   Zac_Jacobson  
Posted On:   Wednesday, September 18, 2002 11:35 AM

You can get it from a shell script that you start your process with. Here's something I copied from an init script I made, you'll have to set these variables to what works for you:
echo -n "Starting $DESC: "
cd $BASEDIR
if [ -e $PIDFILE ]; then
echo -n "Already running."
else
$JAVA $ARGS > /dev/null 2>&1 &
echo $! > $PIDFILE
echo -n "$NAME"
fi
echo "."
The line
echo $! > $PIDFILE
is what saves the process number into a file indicated in the variable PIDFILE.
About | Sitemap | Contact