Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

find out the process id from a background running script

Johnny_hunterJan 18 2012 — edited Jan 19 2012
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 16 2012
Added on Jan 18 2012
6 comments
636 views