Sponsored Content
Top Forums Shell Programming and Scripting Kill -9 within Bash script kicks out usage info Post 302332610 by mglenney on Thursday 9th of July 2009 03:06:18 PM
Old 07-09-2009
Kill -9 within Bash script kicks out usage info

I have a start|stop|restart script for a custom app we have. After it tries to stop our process the correct way, it checks to see if it's gone, if not it tries to kill it, if that doesn't work kill -9.

If I run kill -9 on the PID from the command line it kills it and all is well. If I have the same command within my script it kills it properly, but it also kicks out some usage info. I know I could redirect stdout/stderr for the kill command within the script but I'd rather not if possible.

Here's the code snip:

Code:
  # Check running processes against our list of targets.  If any of
  # them are still running try to kill.
  stoptargetcount=${#stoptargets[@]}
  for ((i=0;i<$stoptargetcount;i++)); do
    found=0
    for ((j=0;j<$resincount;j++)); do
      if [ "${stoptargets[$i]}" == "${instancename[$j]}" ]; then
        found=1
        killjavapid=${javapid[$j]}
        killwrapperpid=`ps alx | grep $killjavapid | grep -v "grep" | awk '{ print $4 }'`
      fi
    done
    if [ $found -eq 1 ]; then
      if [ $pass -eq 1 ]; then
        echo "${stoptargets[$i]} appears to be hung.  Attempting kill..."
        sudo kill $killwrapperpid
        sudo kill $killjavapid
        waiting 5
      elif [ $pass -eq 2 ]; then
        echo "${stoptargets[$i]} is still hung.  Attempting kill -9..."
        echo "WARNING - This may result in zombied child processes"
        sudo kill -9 $killwrapperpid
        sudo kill -9 $killpid
        waiting 5
      else
        echo "ERROR - There appears to be something wrong with the script...exiting"
        exit 1
      fi
      recheck=1
    fi
  done

and the output...

Code:
Checking instance selection...
inst04 found
inst02 found
Stopping instances...
Waiting 5 seconds...
inst04 appears to be hung.  Attempting kill...
Waiting 5 seconds...
inst02 appears to be hung.  Attempting kill...
Waiting 5 seconds...
inst04 is still hung.  Attempting kill -9...
WARNING - This may result in zombied child processes
usage: kill [ -s signal | -p ] [ -a ] pid ...
       kill -l [ signal ]
Waiting 5 seconds...
inst02 is still hung.  Attempting kill -9...
WARNING - This may result in zombied child processes
usage: kill [ -s signal | -p ] [ -a ] pid ...
       kill -l [ signal ]
Waiting 5 seconds...

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

diskspace usage info

Anybody can help me? I need to know a specified folder diskspace usage, that's how much bytes that folder and its files/folders below spend on my storage. Thanks (2 Replies)
Discussion started by: nusajunus
2 Replies

2. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

3. UNIX for Dummies Questions & Answers

kill/pkill process by CMD info.

I have a process that I'd like to kill. Doing a "ps -fu myusername" gives me: UID PID PPID C STIME TTY TIME CMD myusername 5443 1 0 10:05 ? 00:00:00 /bin/sh /some/path/crap.sh -s /yet/another/path/parentProcess myusername 5593 5443 0 ... (2 Replies)
Discussion started by: mrwatkin
2 Replies

4. Shell Programming and Scripting

Help with bash script - Need to get CPU usage as a percentage

I'm writing a bash script to log some selections from a sensors output (core temp, mb temp, etc.) and I would also like to have the current cpu usage as a percentage. I have no idea how to go about getting it in a form that a bash script can use. For example, I would simply look in the output of... (3 Replies)
Discussion started by: graysky
3 Replies

5. Shell Programming and Scripting

Run a bash script, display on the screen and save all information in a file including error info

Hi all, How to: Run a bash script, display on the screen and save all information in a file including error information. For example: I have a bash script called test.sh now I want to run the test.sh and display the output on the screen and save the output including error info to a file. ... (1 Reply)
Discussion started by: Damon sine
1 Replies

6. Shell Programming and Scripting

Bash script show Kill system output

Hi we are calling kill -9 $pid command from bash script it gives below output, but we need to hide the output. i tried /dev/null but ni luck. is there any alternate way to schive this. ../kill_scr.sh: line 42: 1891 Killed /tmp/anr_rest_mul_wc.sh Soalris 10. ... (2 Replies)
Discussion started by: sachinbutala
2 Replies

7. UNIX for Dummies Questions & Answers

usage of kill

i'm writing a code that passes the shells process id and the time set till the pid is killed. the argument from the terminal looks like this: ./timeout $$ 4 now $$ specifies the shell pid, how can insert that to kill(pid,signum) as an parameter? (0 Replies)
Discussion started by: l flipboi l
0 Replies

8. SCO

Console GUI kicks me after 30 seconds. Licensing issue?

I have two SCO servers. On one I can logon to the gui via console with no problem. However, on the other I can logon to the gui but after a few seconds it kicks me back out to the prompt. I asked previous admin about this and he seems to think its a license issue? (7 Replies)
Discussion started by: herot
7 Replies

9. Shell Programming and Scripting

Bash Info Display

I have written the following bash function prArgv Suppose the calling sequence is as follows prArgv VAL1 VAL2 DESC VAL3 VAL4 v2d1 s4 p15 The call will look at the tag k1v2, add the numbers together, in this case 2+1=3 This means that the function will look at the first 3 user arguments... (1 Reply)
Discussion started by: kristinu
1 Replies

10. UNIX for Dummies Questions & Answers

Kill a program from bash

to kill a program in bash, for instance 'mousepad' I use kill $(pidof mousepad); or pkill mousepad But it only works if we use another bash window; If it is started from the same bash, that does not work: #mousepad;kill $(pidof mousepad); In this case, it looks like mousepad hangs... (7 Replies)
Discussion started by: arpagon
7 Replies
KILL(1) 						      General Commands Manual							   KILL(1)

NAME
kill, broke - print commands to kill processes SYNOPSIS
kill name broke DESCRIPTION
Kill prints commands that will cause all processes called name and owned by the current user to be terminated. Use the send command of 81/2(1), or pipe the output of kill into rc(1) to execute the commands. Kill suggests sending a kill note to the process; the same message delivered to the process's ctl file (see proc(3)) is a surer, if heavy handed, kill, but is necessary if the offending process is ignoring notes. Broke prints commands that will cause all processes in the Broken state and owned by the current user to go away. When a process dies because of an error caught by the system, it may linger in the Broken state to allow examination with a debugger. Executing the commands printed by broke lets the system reclaim the resources used by the broken processes. SOURCE
/rc/bin/kill /rc/bin/broke SEE ALSO
ps(1), stop(1), proc(3) KILL(1)
All times are GMT -4. The time now is 03:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy