The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: check whether a process is alive or not
mainienator
Newbie
Rank: 1



UID 245
Digest Posts 0
Credits 0
Posts 24
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:35 AM  Profile | P.M. 
check whether a process is alive or not



check whether a process is alive or not



hi everybody

i have small requirement that needs to be implemented in shell script.
currently i have shell script which invokes a java process say "process a" which runs in background.

if some one tries to invoke again the same shell script , then there should be some mechanism inside the shell script to check whether process "process a"(background process) is running already or not.if it is already running ,it shud not spawn new process "process a" again.

on a simple way i can rephrase it as "at any point of time, there should be only one process(background) running which is been invoked by shell script".if the same shell script is again invoked ,it shud not start the process till it is shutdown.


another info i need is

basically i have process id of background process which is running currently.
i want to check whether the process that belongs to the process id is alive or not .....

reply wud be very much appreciated


Top
Visage
Newbie
Rank: 1



UID 24
Digest Posts 0
Credits 0
Posts 57
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:35 AM  Profile | P.M. 
quote:
originally posted by appleforme1415
[...]
basically i have process id of background process which is running currently.
i want to check whether the process that belongs to the process id is alive or not .....
[...]




code:
$ sleep 5 &
[1] 24814
$ ps -p $! || echo "not running"
   pid tty      time cmd
24814 pts/1    0:00 sleep
$
[1]+  done                    sleep 5
$ ps -p $! || echo "not running"
   pid tty      time cmd
not running

if your ps doesn't support the p option, use "...|grep <pid>"
Top
carljohn
Newbie
Rank: 1



UID 83
Digest Posts 0
Credits 0
Posts 28
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:35 AM  Profile | P.M. 
quote:
originally posted by radoulov
code:
ps x | grep '[j]ava yourapp'||java yourapp



am sorry,
what is the need for 2 pipes
Top
 

 

All times are GMT, the time now is Mar 11, 2010 08:20 PM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.005662 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP