|
Removing defunct httpd processes
I have come up with this little one liner to remove defunct httpd processes (which seem to linger forever unless I kill their parent process):
ps aux | grep defunct | egrep -v "grep|root" | awk '{print "cat /proc/" $2 "/stat"}' | sh | awk '{print $4}' | xargs kill > /dev/null 2>&1
The issue is, seemingly at random it will take down httpd full stop. I thought I could perhaps mitigate that and added the:
egrep -v "grep|root"
line to exclude the main root process of Apache from ever being included in the processes to be killed yet it has happened once again. I must stress the function does work, it works many many times then every so often kills Apache totally!
This is the message you'd expect from the Apache error logs:
[notice] caught SIGTERM, shutting down
when it happens.
Can anyone spot the probably obvious mistake I've made?
Thanks,
cg
|