How about this -
ps -e | awk '$4~/<process name>/{print $1}' | xargs kill
Example:
[jaypal:~/Temp] sleep 100&
[1] 74863
[jaypal:~/Temp] ps -e | awk '$4~/sleep/{print $1}' | xargs kill
[1]+ Terminated: 15 sleep 100
Update:
Sorry, this obviously does not meet the requirement of less typing so a good way of doing it would be to add a function
to your .bashrc
, .profile
or whatever the startup script. The function can be something like this -
killp() {
awk -v pname="$1" '($4==pname){print $1}' <(ps -e) | xargs kill
}
Once added, you can simply pass the name of your process:
[jaypal:~] sleep 100&
[1] 77212
[jaypal:~] killp sleep
[1]+ Terminated: 15 sleep 100
pkill
has been invented for it. – cachius Sep 08 '22 at 17:36