Sponsored Content
Full Discussion: Catch Zombie Process
Operating Systems AIX Catch Zombie Process Post 302570334 by wilsb8 on Thursday 3rd of November 2011 04:36:47 AM
Old 11-03-2011
Quote:
Originally Posted by ckwan
Hi All,
Anyone have any shell script to capture the zombie process, as according to the support they need the real time zombie PID, they only provide the
kdb
(0) > p* |grep -i defunct

(0) > p * | grep <hex pid>

But this is doesn't seem easy to catch the zombie as it is not always appear in the process.

wish someone can shed some light on this. Thanks
Yeah...it's not that simple.

Code:
#!/bin/bash
# zkill - zombie process killing script
# Must be run under root.
case "$1" in
--admin)
        stat=`ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"`
 
        if ((${#stat} > 0));then
    	    echo zombie processes found:
	    echo .
	    ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"
	    echo -n "Kill zombies? [y/n]: "
	    read keyb
	    if [ $keyb == 'y' ];then
		echo killing zombies..
		ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print$4" status:"$10}' | grep "status:Z" | awk '{print $1}' | xargs -n 1 kill -9
	    fi
	else
	    echo no zombies found!
	fi
;;
--cron)
	stat=`ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"`
        if ((${#stat} > 0));then
        ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print$4" status:"$10}' | grep "status:Z" | awk '{print $1}' | xargs -n 1 kill -9
	echo `date`": killed some zombie proceses!" >> /var/log/zombies.log
	fi
;;
*)	echo 'usage: zombies {--cron|--admin}'
;;
esac
exit 0

Best thing to do is run this under cron so you'll be copying this script (assuming you have root privileges) to /bin and then make a cronjob to run it as often as you think it necessary to run.

Hope that helps.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Zombie process

How do i kill a zombie process. Is it that only root can kill a zombie process. (8 Replies)
Discussion started by: orca
8 Replies

2. UNIX for Advanced & Expert Users

Zombie process

I would like to create a zombie process so that I can test monitoring software functionality. Any techniques? (2 Replies)
Discussion started by: swhitney
2 Replies

3. Linux

zombie process

Hi What is the command to find only the zombie processes?? How to write the code in C to fetch the no. of zombie processes?? Thanx (5 Replies)
Discussion started by: jeenat
5 Replies

4. Linux

How to kill zombie process

I have RHES4 machine with VRTSralus - Backup Exec agent installed there and running as a service. The agent hiccups sometimes and turns into defunct state. The problem is that I cannot kill it anyway., it stays there forever until the machine is rebooted. I wonder if anyone had such an experience... (1 Reply)
Discussion started by: will_mike
1 Replies

5. UNIX for Dummies Questions & Answers

How do you create a zombie process?

I'm very new to UNIX, so I need some help please. How do I create a zombie process with just basic UNIX commands (no script, C, PERL, etc)? Please give an example. Thanks. (6 Replies)
Discussion started by: teiji
6 Replies

6. Shell Programming and Scripting

Zombie process

Hi I need help because I don't know if it is possible to add a find inside a cat. like I have a file with the pid of the process that use to became zombie. And I have the same pid stored in the var (pid1) now, I have no clue how to check if the the find finds the pid or even if it's... (2 Replies)
Discussion started by: ruben.rodrigues
2 Replies

7. Solaris

zombie process

dear friends, in an interview they asked me what is zombie process. how we can identifying these process.if can you kill all zombie process. (8 Replies)
Discussion started by: sijocg
8 Replies

8. AIX

zombie process

Is there an equivilant to the preap command in AIX that would allow me to get rid of a zombie process. I am new to AIX, moving over from Solaris and in the past I have been able to preap the pid on the defunct process to clean them up. I have looked around and the best I can see is that it may... (3 Replies)
Discussion started by: sboots
3 Replies

9. UNIX for Advanced & Expert Users

Zombie process

What is the overhead associated with zombie process?Is it running out of process-ID?:confused: Since some information is stored in process table.. Thanks in Advance (4 Replies)
Discussion started by: jois
4 Replies

10. Red Hat

How to get rid of zombie process?

Hi, How to get rid of Zombie Process, Kill -9 PID does not seem to be permanent solution, your help will be Appreciated. Thanks (11 Replies)
Discussion started by: szs
11 Replies
GREP(1) 						      General Commands Manual							   GREP(1)

NAME
grep - search a file for lines containing a given pattern SYNOPSIS
grep [-elnsv] pattern [file] ... OPTIONS
-e -e pattern is the same as pattern -c Print a count of lines matched -i Ignore case -l Print file names, no lines -n Print line numbers -s Status only, no printed output -v Select lines that do not match EXAMPLES
grep mouse file # Find lines in file containing mouse grep [0-9] file # Print lines containing a digit DESCRIPTION
Grep searches one or more files (by default, stdin) and selects out all the lines that match the pattern. All the regular expressions accepted by ed and mined are allowed. In addition, + can be used instead of * to mean 1 or more occurrences, ? can be used to mean 0 or 1 occurrences, and | can be used between two regular expressions to mean either one of them. Parentheses can be used for grouping. If a match is found, exit status 0 is returned. If no match is found, exit status 1 is returned. If an error is detected, exit status 2 is returned. SEE ALSO
cgrep(1), fgrep(1), sed(1), awk(9). GREP(1)
All times are GMT -4. The time now is 11:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy