2 Questions about my process control script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 2 Questions about my process control script
# 1  
Old 04-13-2006
2 Questions about my process control script

Hi all,

My tiny mind is struggling with the following script that shuts down Tomcat on Sol. 8 and kills any defunct processes Tomcat might leave behind (as it so often does). I realize that fixing Tomcat would be best, but this is a band-aid so I won't have to do as much off-hours support of this pig, which will hopefully buy me time to research the matter more thoroughly.

Anyway, on to the goods...

Code:
#!/bin/sh
# variables
tcpid=`ps -ef |grep java |grep -v grep |sort |awk '{print $2}'`
signal=9
tclog=/opt/local/jakarta/logs/catalina.out
now=`date +'%Y%m%d%H%M'`

# Shutdown Tomcat
/opt/local/jakarta/bin/shutdown.sh

sleep 20

if [ $tcpid != "" ]
do
    (sudo kill $signal) $tcpid
        sleep 5
else [ $tcpid = "" ]
        echo "Java Stopped"
done

# manage catalina.out, cache dirs and core dumps
cp $tclog /opt/local/jakarta/logs/catalina.out.$now
>/opt/local/jakarta/logs/catalina.out
gzip /opt/local/jakarta/logs/catalina.out.$now
rm -rf /opt/local/jakarta/work/Apache/*
find /opt/local/jakarta/ -name core |xargs rm
# wait for tomcat cache to clear
sleep 30

# restart this pig
/opt/local/jakarta/bin/startup.sh

exit

So far, my problems are in this segment:

Code:
if [ $tcpid != "" ]
do
    (sudo kill $signal) $tcpid
        sleep 5
else [ $tcpid = "" ]
        echo "Java Stopped"
done

I want to see if the pid still exists (thus is defunct, needing sudo to kill), then kill -9 it every 5 seconds or so until it goes away. Once it's gone, it can move on to the rest of the script.

What this one's doing is looping infinitely _and_ I keep getting errors about it trying to kill a process called '-9'. I've tried

`sudo kill -9 $tcpid` or (sudo kill -9 $tcpid), but to no avail.

Anyway, any pointers for how I can effectively pull this off?

Thanks!

Dave
# 2  
Old 04-13-2006
I've tried this type of while loop too (since I think a while loop makes more sense for what I'm trying to do):

Code:
while [ $tcpid != "" ]
do
    (sudo kill -9 $tcpid)
    sleep 5
done

It runs regardless of the whether $tcpid is running or not, and it too loops until I manually kill it.

I see in my script above my signal variable was only '9' and not '-9'. I've tried both ways and that doesn't work either.
# 3  
Old 04-13-2006
Let's say that the pid is 1612. So you set tcpid to 1612 and then you enter your loop. On the first iteration you kill the process. After the process dies, the value of $tcpid will not magically change values for you. It is still 1612. It will stay 1612 forever since you don't assign it a new value in the loop.

What is the point of the loop anyway? If a process survived a "kill -9", do you think that second "kill -9" will work any better?
# 4  
Old 04-13-2006
Thanks for the reply. I'll try it with the full command (thus re-evaluating whether the pid exists) to see if that helps.

Regarding your question, the process may not sustain a kill -9 over a prolonged period of time, but it takes so long for it to stop, that I've found just spamming signals its way kills its defunct process. The goal is to bring the process down and up as soon as possible.

Cheers,

Dave
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to continue shell script execution process without control going to pompt?

Hi Friends, Iam invoking another shell script to create B2k_session_id from my shell script.It is properly creating B2k_session_id and after creation control is coming out from the script and going to command prompt.The lines which are after the exectrusteduser.com sh.com are not executing..may... (5 Replies)
Discussion started by: vadlamudy
5 Replies

2. Shell Programming and Scripting

control timeout of sqlplus process

Hi, I'm using simple sqlplus to test DB availability. When DB is going down, sqlplus command is hang for a few minutes I want to implement the following: 1. execute sqlplus 2. if after 20 sec I dont get a response, kill the process and exit with error. 3. if I get immediate response... (2 Replies)
Discussion started by: gdan2000
2 Replies

3. Shell Programming and Scripting

job/process scheduling or control

Hi forum, I have a problem concerning job or process scheduling and control. I have to run 24 jobs (could be more sometimes less) of the same programme with different parameters. The machine this code is running on is an 8-core machine, so I was thinking that running all the processes at once... (0 Replies)
Discussion started by: deiphon
0 Replies

4. UNIX for Advanced & Expert Users

Control process from different terminal (over SSH)

I pressed CTRL Z and suspended the job. then I pressed bg, The process re-started to throw output on the terminal and its not allowing me to access the prompt. its not even accepting CTRL Z. The process has been running for about 2 hours now and I want to suspend it by opening another terminal.... (3 Replies)
Discussion started by: rakeshou
3 Replies

5. Shell Programming and Scripting

How to control/overide shutdown/reboot process?

Dear all, I want to control my server from shutting down and rebooting. It will ask for some question before the process, ex: who are you? what is the reason for shutting down? ... I think I can overide that binary of shutdown/reboot command, but it is confused. We have many way to... (5 Replies)
Discussion started by: fongthai
5 Replies

6. UNIX for Dummies Questions & Answers

init and process control

I'm trying to wrap my head around process control in Unix... particularly init and how it fits in to the equation. Init is responsible for creating sessions by spawning instances of getty which calls login effectively creating sessions right? Why then can init belong to a session? If you ps jx... (4 Replies)
Discussion started by: dexfantasy
4 Replies

7. UNIX for Advanced & Expert Users

control the process

I found that in my system , there are some strange process , it will make the system crash so I would like to control the system no such process is running , this is if the system process that its process name is "ora" AND its ppid is not "2" , then it will crash the system, can suggest how to... (2 Replies)
Discussion started by: ust
2 Replies

8. Programming

Reading a process control block

Hello, I want to know what call to use to read the details of a process control block in solaris ?:) (2 Replies)
Discussion started by: hmurali
2 Replies

9. Filesystems, Disks and Memory

unix process control

can anyone send me enything about "unix process control " nicko@freemail.com.mk (2 Replies)
Discussion started by: nicko
2 Replies
Login or Register to Ask a Question