FUN WITH UNIX PROCESSES

1.  Log on to your linux machine.

2.  Try top.  Do a man of top to see how you can get it to run just once and
	pipe its output to a file called foo.

3.  Have a look at foo.  Recognize any of the processes?  Some of them should
	be yours.  You should actually see your top process in the list of
	processes.

4.  Try top -b | grep top.  This should show just the processes that have
	the word top in them.  Maybe there are a few such processes.

5.  Let's create a few processes.  Gawk is a good language for making
	processes.

	Write the file to the filename foo.awk:

	BEGIN {
	  print "you are a fool!"
	  print "kill me if you can!"
	  system("sleep 5")
	}

	Now say 

	gawk -f foo.awk &

	You should have a process sitting in the background that is
	sending rude messages to you every five seconds.

	It's possible the process suspends if it can't write to your terminal.
	But that's ok, you still want to kill it.

6.  Start a few more of these evil background processes, again with
	the gawk command.

7.  Now run top.  Do you see the processes?  Can you kill them manually?
	You can do it by using kill at the command line, or by using the
	k command within top.

8.  Try top -b | grep foo

	In fact, try top -b | grep foo | gawk '{print $1'}.

	This should just list the process id's you want to kill.

9.  As long as you are learning a bit of gawk, here is the program you
	want, police.awk:

	BEGIN {
	  system("sleep 30")
	  com = "top -b | grep foo"
	  while (com | getline) {
	    print "killing "$1
	    system("kill "$1)
	  }
	  close(com)
	}

	You invoke it by saying... well, your turn to guess.

	This should kill all of the foo processes every 30 seconds.  Try it.

	Try launching a bunch of gawk -f foo.awk and see if police.awk wakes
	up and kills them.

10.  Can you write a script called policepolice.awk which wakes up
	every sixty seconds and kills any police.awk that is running?

	Does your script have any interesting properties, such as a
	penchant to commit suicide?  How can this be prevented?