Check whether a process is alive or not


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Check whether a process is alive or not
# 15  
Old 05-31-2007
Quote:
Originally Posted by radoulov
Logical OR.



You don't need it when checking $count == 0 ...
Silly me!

I didnt have the patience to think the other way.

The command had a pipe and thought the other two ( '||' ) were also pipes.


Thanks ! Smilie
# 16  
Old 05-31-2007
Quote:
Originally Posted by radoulov
Code:
ps -p $! >&- || echo "not running"

If the above doesn't work use:

Code:
ps -p $! >/dev/null||echo "not running"

Thanks for the reply.

Both command worked partially....

i have intiated a process
Code:
sleep 50 &

then i execute the both commands alternatively , both commands did not get me any outputas the process is alive ...when sleep process finishes, both these commands returned me output
Quote:
[1]+ DONE sleep 50
not running
In the above case ,i need only the output "not running"
can help me on this.....
# 17  
Old 05-31-2007
Quote:
Originally Posted by appleforme1415
Thanks for the reply.

Both command worked partially....

i have intiated a process
Code:
sleep 50 &

then i execute the both commands alternatively , both commands did not get me any outputas the process is alive ...when sleep process finishes, both these commands returned me output


In the above case ,i need only the output "not running"
can help me on this.....
If you run the command interactively disble monitor first

Code:
set +m
...

Within your script you won't get that output.
# 18  
Old 05-31-2007
Quote:
Originally Posted by radoulov
If you run the command interactively disble monitor first

Code:
set +m
...

Within your script you won't get that output.

I am going to run all the commands which i discussed in this forum as a shell script in prod environment.

Wil there be any impact on executing the command "set +m " in Prod environment...

Suppose if i execute the command "set +m" within my shell script it will have its impact only to that shell script ....right ???

Without doing that will there any way to overcome it.....
Kindly advice me on this issue.....
# 19  
Old 05-31-2007
Quote:
Originally Posted by appleforme1415
I am going to run all the commands which i discussed in this forum as a shell script in prod environment.

Wil there be any impact on executing the command "set +m " in Prod environment...
[...]
No.

Quote:
Suppose if i execute the command "set +m" within my shell script it will have its impact only to that shell script ....right ???
Yes, but as already stated, you don't need that command inside a script.
# 20  
Old 05-31-2007
Hammer & Screwdriver

Let me summarize whole thing in a single reply as per the valuable response from the forum members

Code:
CLASSPATH=.
CLASSPATH=${CLASSPATH}:sampleswing.jar
value = $(ps -p $! >&- || echo "not running")

if [ $value == "not running" ] then
 nohup java -cp ${CLASSPATH} Sample > /dev/null 2>&1 &
 echo "kill -9 "$! > killer.sh
 chmod 777 killer.sh
fi


Kindly correct me if there is any mistake in "If construct" syntax....
As i am totally new to Unix, it is bound to happen...
# 21  
Old 05-31-2007
Quote:
Originally Posted by appleforme1415
Let me summarize whole thing in a single reply as per the valuable response from the forum members

Code:
CLASSPATH=.
CLASSPATH=${CLASSPATH}:sampleswing.jar
value = $(ps -p $! >&- || echo "not running")

if [ $value == "not running" ] then
 nohup java -cp ${CLASSPATH} Sample > /dev/null 2>&1 &
 echo "kill -9 "$! > killer.sh
 chmod 777 killer.sh
fi


You cannot use $! before executing the program in background.
You can use something like this:

Code:
lockfile="/tmp/my_lock"

[ -f "$lockfile" ]&&mypid=$(<"$lockfile")
if ! ps -p $mypid>/dev/null 2>&1;then
        nohup java -cp ${CLASSPATH} Sample >/dev/null 2>&1 &
        echo $! >"$lockfile"
fi


Anyway, I'd use some unique pattern from the command line:

Code:
ps -ef|grep [S]ample||nohup java -cp ...

If such a pattern does not exists, I'd create one:
Code:
ps -ef|grep [f]oo||nohup java -Dfoo=foo -cp ...


Last edited by radoulov; 05-31-2007 at 11:12 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Tips and Tutorials

My "Bread and Butter" Process Keep Alive Perl Script....

For the newbies, I should have posted this years ago.... Here is the standard (tiny) "bread and butter" perl script (on Linux) I use in my crontab files to insure key processes are alive ( just in case ! ) like httpd, named, sshd, etc. The example below if for named...... ... (1 Reply)
Discussion started by: Neo
1 Replies

2. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

3. UNIX for Dummies Questions & Answers

Check the URL is alive or dead with port number

Hi, I am running certain weblogic instance, in which it's hard to find which instance is stopped or running after stopping the weblogic , cause process status is for all the instance is same. A URL which shows the instance is stopped or running. But i have major challenge to check it through... (2 Replies)
Discussion started by: posix
2 Replies

4. Solaris

keeping a process alive ?

Hello guys, I have one script running that I need to keep it running 24x7 so I'd like to know how can I implement a sort of monitoring process I mean if for some reason this process dies somehow it gets automatically started again. Thanks. (8 Replies)
Discussion started by: cerioni
8 Replies

5. Shell Programming and Scripting

Check process

Hi.. I have this code which tells me that if a process is running or not. Actually someone on this forum help me to do it. :) But now If i want to check if the process is not running for more than 10 minutes. Does anyone know the code or syntax that checks if a process is not running for some... (1 Reply)
Discussion started by: kanexxx
1 Replies

6. Shell Programming and Scripting

How to check if a pid is alive?

I want to do some operations provided the pid is active. (6 Replies)
Discussion started by: ScriptDummy
6 Replies

7. UNIX for Dummies Questions & Answers

Check the process

Except the command "top" , is there other function / tool is used to check the process status in the system like 1. what process are running ? 2. how the CPU are allocating ? 3. how many swap is using ? 4. " Thx. (1 Reply)
Discussion started by: ust
1 Replies

8. Shell Programming and Scripting

check the process

how to kill the process that are idle over 30 minutes ? thx (2 Replies)
Discussion started by: ust
2 Replies

9. UNIX for Advanced & Expert Users

Check the process

I want to find the pid ( by ps ) that has already run over 30 seconds , I know ps only show the minute/hour . eg. the start time of the below process are 15:19 / 15:20 , but I don't know the exact time ( in term of "second" ) it start to run ( I only know the hour and minute ) , if I want to... (2 Replies)
Discussion started by: ust
2 Replies

10. Shell Programming and Scripting

check if job still alive and killing it after a certain walltime

Hi! I'm using a script to start a process that might run forever if some parameters are given wrong (it's part of an optimization). I would now like to have the process killed after a certain walltime in that case. So far I get it done with the following lines ./My_process.e & pid=`ps -ef |... (3 Replies)
Discussion started by: ciwstevie
3 Replies
Login or Register to Ask a Question