Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to capture the PID of a process using nohup

Status
Not open for further replies.

newDBA

MIS
Nov 8, 2001
21
0
0
FR
I need to start a process in the background and using nohup, and I need to capture the PID of that process. I know that I can use $! to capture the PID of the last process started in the background, but that doesn't work when using nohup.
Any suggestions how to capture the PID when using nohup and running it in the background?
 
Hello:

I don´t know if this is what you are looking for but if you know the name of the command you execute with nohup you can use the following command:
ps -ef|grep command|grep -v grep|awk '{ print $2 }'

Regards.
 
In this situation I cannot use a "ps -ef" because I am launching a Java process, and there is no way to differentiate among the different processes using a grep. So...I have to capture the PID.
 
I was wondering if you ever found the solution to capturing the PID when nohuping a process in the background. I've been trying a variety of redirections but nothing seems to work.
Regards.
 
Are you sure?
Do you use HPUX?
On my machine it work. (HPUX 10.20.)


nohup sleep 102&
pid=$!
ps -ef |grep " $pid "|grep -v grep " $pid "

output:
root 1649 20130 2 14:04:58 ttyrf 0:00 sleep 102


Regards Gregor. Gregor.Weertman@mailcity.com
 


I sorted it out, I'm not sure if this solves the original post but here it is. I'm new to this unix stuff)....I have one script that launches the processes and records the pID of the processes to a file .....

nohup java_app1 &
echo $! >> pid.file

nohup java_app2 &
echo $! >> pid.file

etc...

.............A second script will cycle through the PID's in the file and kill the apps/vm's......at my whim.....

please excuse the excessive use of ..........






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top