Killing a while loop that's running in the background without a PID

Viewed 7610

I'm a beginner in everything that is part of Linux so please take me slow.

I've created a "script" that's running in the background:

while true; do echo "I'm alive" >> alive.log ; done &

The output of the script is saved in a file alive.log that's present in the user's home directory. The problem is I have no ideea how to kill the loop since it's filling my disk space, if I wish to delete the file then loop will create a new file and fill it with the text "I'm alive" as I've asked it to do.

I tried using:

ps - aux | grep while

or

ps - aux | grep alive 

The output for the two lines will give me the PID I need but the problem is that the script is a loop which means the PID will change every time it runs itself (recursive) so I can't use the PID to kill the process.

I also tried using:

pkill while
killall while

The result for both lines is 0 (output can be seen when using pkill while -c "0" or killall while : "while: no process found";

Any suggestions please?

5 Answers

This is an answer by @James Brown in the comments.

Type fg to get it in the foreground and kill it with ctrl-c the fastest way to solve this.

Related