Hello all:
I created a java service and use a shell script to drive it from background. In the script, I have code like this:
javac myApp &
I want to find out the pid for this process. After googling for a while I came up with this:
echo $$ > test.pid
However, I notice two things:
1. This only works when my script runs frontground, meaning only when I remove "&";
2. The pid file, test.pid, won't be created until the running script exits, after I clicked ctrl+c, for instance.
Now the question is, how can I find out the pid of a background running script from within the script itself?
I don't want to use code such as
ps -ef | grep ....
because of the possible name conflict.
Thanks,
Johnny