I was learning bash with a book called learning the bash shell. All was well until I came across the kill command. I created a little script called loop, then ran it using loop &. When I use kill %loop, then use ps -e | grep loop, the process is still there. So did I fail to kill it? Do I have to use kill -9? Also,pidof seemed to not work at all when I use pidof loop. It returns nothing at all.
I am using Ubuntu and bash. Although I think the script shouldn’t matter, here it is just in case:
#! /bin/bash
# Just a script
while true; do
sleep 60
done
Shell scripts don’t run as the name of the script. They run as the name of the shell you specify in the shebang. In your case, that’s
/bin/bash. If you’d donepidof bashyou’d have gotten the pid of your script (along with all the other bash scripts running at the time).That being said, you can’t kill scripts by their name, as you’re trying with
kill %loop. Kill only accepts pids. If you’re using the%notation, then that refers to the internal job number assigned by the shell. e.g, using your loop script as an example: