I have a function in bash to kill all the processes, which contain the same name:
killn () { pkill -9 -f $1; }
I realize that tcsh does not support functions.
How I can translate this function into an alias that will work in tcsh?
First, a warning to anyone who stumbles upon this post: the -f
flag to pkill
will cause it to match the pattern you give it with the full command line of each process rather than just the process's name. This matches more processes, so you may end up killing more than you intend. Be careful!
Since the pattern you are passing to pkill
appears at the end of the command, you don't actually need explicit argument handling, so this can be done with the simple kind of tcsh
alias:
alias killn pkill -9 -f
With that alias defined, if you want to send SIGKILL
to processes whose full command lines contain a match to pattern
, you use the alias like this:
killn pattern
That substitutes pkill -9 -f
for killn
, causing your desired command to be run:
pkill -9 -f pattern
Note to casual readers: this is a tcsh
alias, which does not have the same syntax as a bash
alias.