Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

Identifying new processes IDs

SOLVED
Go to solution
Mike Rightmire
Frequent Advisor

Identifying new processes IDs

I have a software package which startsa jre to run. However I have a number fo other packages that also start a jre when they are running. I need a solid method of identifying which jre is started by which process and the PID of that jre.

I had thought about simply doing a search for the pid pf the jre (using ps) as soon as I started the process, however (in theory if not practice) this could allow for the PID of another jre started at the exact same time to be reported.

I remember there being a command which reports back the process ID of a new process as soon as it is started from a script, however I cannot remember what that command is.

If anyone out there knows the command, or a better way to do this, I would be grateful!'

Thanks!
Mike
"If we treated each person we met as if they were carrying an unspeakable burden, we might almost treat each other as we should." Dale Carnegie
3 REPLIES
Santosh Nair_1
Honored Contributor
Solution

Re: Identifying new processes IDs

I believe you're looking for the environment variable $!. This returns the PID of the last background command.

-Santosh
Life is what's happening while you're busy making other plans
Sachin Patel
Honored Contributor

Re: Identifying new processes IDs

Hi Mike
$! is the pid of last process.

Try this two command on command line for more understandig of what you receiving.
#sleep 10000 &
#echo $!

Sachin
Is photography a hobby or another way to spend $
Bill Thorsteinson
Honored Contributor

Re: Identifying new processes IDs

As noted $! will allow the starting program to
identify the PID of the java process just started.

I use a couple of techniques to make it easier to
identify which process is which. First, I define
the process or task as the first parameter to the
java process. Then I echo the PID to a pid file

java -D task.$mytask ....
echo $! > $PIDDIR/$mytask.pid

I can then look at the command string to find out which
task owns the VM, or check the pid files to find the
VM if it is still running. You can use the PID file to make
sure you don't run multiple copies of the same task.