Script which uses “kill -9” command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script which uses “kill -9” command
# 1  
Old 08-15-2010
Script which uses “kill -9” command

i have one script which uses “kill -9” command. That prevents from getting the process core dumps. Apparently once tomcat lands in a confused state, we seem to have no other option, other than Kill -9.

is there any other way to get rid of this.

Script:

Code:
sleep 2
PID=`ps -ef | grep "^tomcat " | grep -v grep | grep Bootstrap | awk '{print $2}'`
if [ "$PID" != "" ] ; then
  echo "Killing process."
  kill $PID
  sleep 5
  PID=`ps -ef | grep "^tomcat " | grep -v grep | grep Bootstrap | awk '{print $2}'`
  if [ "$PID" != "" ] ; then
    echo "Force killing process"
    kill -9 $PID
  fi

Any idea will be highly appriciated

Moderator's Comments:
Mod Comment Neo: Changed Thread Title for User. Please follow forum rules and use a descriptive subject text useful to others.

Last edited by Amrutayan09; 08-15-2010 at 12:24 PM.. Reason: Added code tags; removed formatting
# 2  
Old 08-15-2010
Off the top of my head, I'd say that tomcat is ignoring TERM (15) signals (the default when you only provide a PID to the kill command). This is why 'kill $PID' seems not to work. It is likely ignoring HUP (1) and QUIT (3) signals too.

Quote:
is there any other way to get rid of this.
I'm not really sure what this is that you are wanting to get rid of. The running process, the script, the need for kill -9?

I'll go on the assumption that you are wanting to cause a core dump which is not produced when using -9 (SIGKILL). Try using 'kill -6' (abort) -- I'd hope that the tomcat developers left this signal set to it's default value (terminate programme and generate a core dump).

Last edited by agama; 08-15-2010 at 12:50 PM.. Reason: fixed typo
This User Gave Thanks to agama For This Post:
# 3  
Old 08-15-2010
Thanks for your reply.

Yes u r correct, i want the core dump which is not produced using kill -9.

can i use kill -3 ?

Thank you very much for giving me an way
# 4  
Old 08-15-2010
You can try kill -3, however that signal is often disabled or caught and processed by daemons such as tomcat. If it works, great, but I wouldn't be surprised to find that it has the same effect as kill -15. I don't run tomcat, so I can't play round with it to tell you more than this.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Trapping a kill command sent to a script and using it to send an EOF to a subprocess before killing

I originally had a script written in pure shell that I used to parse logs in real time and create a pipe delimited file that only contained errors. It worked but it was using a lot of memory (still not clear on why). I originally got around this by writing a wrapper for the script that ran on cron... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

2. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

3. Shell Programming and Scripting

Help with script to stop a user giving kill command on a server!!

Hi, I am new to shell scripting and want to create a script with the follwoing description: I want to restrict the users from giving a kill command on a unix server. The server have a restricted logins with login id and passwords. I want a script that will find out if a user has given a... (9 Replies)
Discussion started by: shell_scripting
9 Replies

4. Shell Programming and Scripting

Perl script to kill the process ID of a command after a certain period

All, I am trying to build a script in perl that will alllow me to pass the IP address to a ping command and redirect the output to a file and then kill that process after a certain period of time. let's say, I call my script ping.pl, I would like to be able to run it like this for example :... (7 Replies)
Discussion started by: Pouchie1
7 Replies

5. Solaris

Help with Kill Command

I am running Solaris 9. I have a problem with kill command. I'm sort of teaching myself so this might be a really stupid thing. I logged in as a normal user, lets say ABC, and then did "su" to root. After becoming root, I tried to kill the process started by ABC by saying kill -9 "pid of ABC" ... (3 Replies)
Discussion started by: the_red_dove
3 Replies

6. Web Development

Rewrite rules to change “link.html?hl=es” to “/es/link.html” etc?

Hey! Does anyone know how to create rewrite rules to change: “link.html?hl=en” to “/en/link.html” “link.html?hl=jp” to “/jp/link.html” “link.html?hl=es” to “/es/link.html” etc? Where "link.html" changes based on the page request? (2 Replies)
Discussion started by: Neo
2 Replies

7. Linux

Kill a process without using kill command

I want to Kill a process without using kill command as i don't have privileges to kill the process. I know the pid and i am using Linux 2.6.9 OS. (6 Replies)
Discussion started by: sudhamacs
6 Replies

8. Shell Programming and Scripting

Kill a process without using kill command

Sorry, posted the question in other forum. (0 Replies)
Discussion started by: sudhamacs
0 Replies

9. UNIX for Advanced & Expert Users

How to kill top command using script?

Hi all, I am using top command in my script to redirect output to temp file. I used kill -9 `ps -ef|grep top|grep -v grep|awk '{print $2}'` to kill top command in my script, but it is not working? Can you please tell how to kill top command in my script? (4 Replies)
Discussion started by: johnl
4 Replies
Login or Register to Ask a Question