Linux / UNIX Tech Support Forum
This is a discussion on killing defunct and orphan process within the Shell scripting forums, part of the Development/Scripting category; Hi Team, I need a shell script which will kill the orphan process and defunct process in my server. Please ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
| Sponsored Links | ||
|
|
|
||||
|
Why script? There are commands that can do same quickly:
Code:
pkill -u user processname pkill -u www httpd pkill -u php php-cgi
__________________
Vivek Gite Linux Evangelist |
|
||||
|
Code:
#!/bin/bash
for x in ps -ef | grep defunct | awk '{print $2}' ; do
kill -9 $x
done
This will echo out the process ID'S of the defunct processes. Good Luck Jaysunn |
|
||||
|
Hi,
The script is fine but my worry is the child Process is not killing. i have to delete the parent process to kill the defunc. Example: Code:
ps -ef | grep defunc Code:
root 2093 2050 0 22:51:29 pts/79 0:00 grep defunc aaaaaaaa 25552 25537 0 - ? 0:00 <defunct> bbbbbbbbbb 2018 2013 0 - ? 0:00 <defunct> bbbbbbbbbb 5170 5152 0 - ? 0:18 <defunct> aaaaaaaa 25548 25537 0 - ? 0:00 <defunct> aaaaaaaa 25363 25338 0 - ? 0:00 <defunct> aaaaaaaa 25356 25338 0 - ? 0:01 <defunct> aaaaaaaa 25373 25338 0 - ? 0:00 <defunct> aaaaaaaa 25791 25781 0 - ? 0:00 <defunct> cccccccc 8478 8384 0 - ? 0:00 <defunct> cccccccc 8466 8384 0 - ? 0:00 <defunct> aaaaaaaa 25341 25338 0 - ? 0:00 <defunct> cccccccc 8474 8384 0 - ? 0:00 <defunct> bbbbbbbbbb 22242 22232 0 - ? 0:24 <defunct> aaaaaaaa 25539 25537 0 - ? 0:00 <defunct> ddddddddddd 13908 13889 0 - ? 0:00 <defunct> aaaaaaaa 25543 25537 0 - ? 0:01 <defunct> ddddddddddd 13952 13911 0 - ? 0:00 <defunct> bbbbbbbbbb 17217 17210 0 - ? 0:03 <defunct> aaaaaaaa 25585 25579 0 - ? 0:01 <defunct> aaaaaaaa 25813 25781 0 - ? 0:00 <defunct> bbbbbbbbbb 17631 17621 0 - ? 0:09 <defunct> aaaaaaaa 25589 25579 0 - ? 0:00 <defunct> bbbbbbbbbb 17724 17717 0 - ? 0:02 <defunct> bbbbbbbbbb 18756 18745 0 - ? 0:03 <defunct> Note: i tried manually to kill the child Process.It's is not working.. After killing the Process I should get a mail saying these are Process got killed like that.. # vi defunc.sh Code:
"defunc.sh" 6 lines, 99 characters
#!/bin/bash
x=0;
for x in `ps -ef | grep defunct | awk '{print $3}'` ; do
echo $x
kill -9 $x
done
"defunc.sh" 6 lines, 98 characters # ./defunc.sh Code:
25537 2013 5152 25537 25338 25338 25338 25781 8384 8384 25338 8384 22232 25537 25101 25150 13889 25537 13911 17210 25579 25781 17621 25579 17717 18745 Last edited by nixcraft; 29-06-2009 at 11:51 AM. Reason: [code] tags added |
|
||||
|
Use killall instead of kill:
Code:
killall -9 process-name Code:
pkill -9 -u user process-name
__________________
Vivek Gite Linux Evangelist |
|
||||
|
Read this tread - Killing zombie process
Especially comment where a few scripts and hacks are posted by users. PHP Code:
__________________
Raj Linux rulz. I have never turned back in my life ; I shall not do so today.. haha |
![]() |
| Tags |
| kill , killall |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Process Killing -9 vs -10 and RAID 0+1 vs RAID 1+0 | amsreeku | Linux software | 1 | 07-07-2008 03:44 PM |
| Killing of a process and send a mail if the process doesnot come up within 2 minutes | Prince89 | Shell scripting | 1 | 11-02-2008 12:39 PM |
| process need more memory | brijesh | Linux software | 3 | 13-12-2007 05:38 PM |
| httpd process | vimalgoel | Getting started tutorials | 1 | 08-10-2007 12:40 AM |
| Help with killing | sparky | Shell scripting | 5 | 14-04-2006 05:52 PM |