Wednesday, January 9, 2008

Zombies

Zombies!! What are they?
Zombies are walking corpses, they sometimes talk but in general they are not very talkative. Zombies being not very talkative is the main problems in dealing with them. However, we can always find them and deal with them. The easiest way to deal with them is to restart, which is not very good in a lot of times.

Zombies
are those children created by a parent process whose parent died before reaping them

In other words, some lousy piece of code written by some lousy programmer that forks children. However, the programmer didn't account for the possibility that the parent might die before its children. The net result of this mess is a bunch of zombies leeching system resources and leaving your machine unsure of the next step.
Reasons to create zombies:
  1. The programmer was really very bored and didn't want to check
  2. The assumption that forked children will be nice and die before their parents
  3. The assumption that the parent will be mean and not die unless kills all children
  4. The assumption that someone will come and kill those children, which actually happens when the init process takes over and clean up things, but this is no execuse
  5. The programmer was out of coffee or time
  6. The programmer needed more time and a more screwed up machine to test his screwed up code
  7. The machine is actually a zombie, so the programmer won't notice more zombies
  8. Zombie infection might have taken over the machine in an unrecoverable way, through open ports. It'll get worse when the infection is done by a tunnel and even worse when the machine doest not have a good antibiotic or vaccinations
Solutions to the above mentioned problems:
  1. The programmer should never feel bored and should keep coding till one of two things happen:
    1. Power outage
    2. Coffee leak
  2. Children are never nice and won't die by themselves. They must be killed and reaped by their parent in a very brutal and gory way
  3. Parents will never bother to reap their children automatically because they are really easy and have the tendency to screw the programmer. The programmer should threaten the parents by issuing random SIG_INT so they'll be afraid of leaving their children alone!!
  4. No one will come and clean zombies processes from your system!! Go wait (kill) them by yourself
  5. Programmer out of coffee is a FATAL error and nothing much can be done about it, responsibility is put on the supervisor! However as for time, the programmer should never relay on the accuracy of time as this electron around the Cesium is not really what you mean by accurate
  6. Time again (please refer to 5). A screwed up machine is very easy (use VISTA)
  7. Programmer is completely responsible for turning the machine into a zombie. The programmer should leave the machine to his/her younger brother or sister if any. If not the programmer should be careful and turn this zombies machine into a coffee machine and proceed to the nearest computer store and to buy some new gear. Things to remember when buying new gear is how easily the new gear is transformable to a coffee machine or cubs holder
  8. Whenever a zombies infection is present on the machine go SLEEP and don't go out under sunlight... it is you the programmer who turned to a zombie
In any event, I was really bored and I wrote this silly shell function to tell me if there are zombies and tried to kill them. Please note that mechanism of killing zombies are beyond the scope of this post. Also, comments are left as an exercise for the reader..

zombies() {
z=`ps aux | awk '{ print $8 " " $2 }' | grep -w Z`
id=${z#Z}
if [ ! -z "$z" ]; then
  echo -e "You have a zombie `whoami`"
  echo "ID: $z"
  ps aux | grep Z
  echo "Killing $id"
  kill -9 $id
else
  echo "No Zombies!!"
fi
}


Ok world, we'll get back to more interesting things like daemons very very soon.. stay tuned :)

No comments: