The 'g' at the end of the sed commands means that the replacement (in this case, you can use this option with most commands) is to occur globally, and not just the first occurrance of the substitution.
The -9 on the kill command pretty much ensures that the process will be killed. It does get more technical than that, but I don't know what specifically it does.
I'll take a stab at the fourth part, but I could be a bit off as I don't normally get to do anything quite that complex.
It looks like the command line for the script would be something like
script file_name arg1 arg2 arg3 ...
The first thing that it does is it takes $1 (file_name) and assigns it to the file variable. The shift causes all of the other arguments to move up in the chain of arguments. I.e., initially, file_name is $1, arg1 is $2, arg2 is $3 and so on. The only problem is that the for loop runs from 1 to 9, and you can't have a $10. So, to get around this, you shift. Then, arg1 is $1, arg2 is $2, arg3 is $3 and so on.
The foreach loop runs allows you to run through those 9 arguments. The $#argv is the number of arguments that was passed to the script (NOTE I do not know if the shift command effects $#argv or not. Perhaps someone wiser and more knowledgable than I would know). So, the If statement says that if $n is less than the total number of arguments, the cmd variable is set to what ever cmd is currently set too, plus your regular expression that gets passed to sed. From my example above, the first time through (n==1), you'd see
sed -e s/$1/arg1/g
If you have say just 2 arguments, it would then go through a second time and set cmd to
sed -e s/$1/arg1/g -e s/$2/arg2/g
and so on until it finally gets to be $n > $#argv.
Then, of course, it kicks the command off in a separate c shell and makes all of the changes to the file that was supplied on the original command line.
Hope that answers your questions without being too wordy (which I tend to get sometimes).
Hobbletoe