Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill a running for loop on linux?

Tags:

linux

pid

I'm working on Linux, I have executed the for loop on a Linux terminal as follows:

for i in `cat fileName.txt`
do
echo $i
vim $i
done

fileName.txt is a file contains the large no of file entries that I'm opening in vim editor one by one. Now i have to skip opening other files in between.(i.e. i have to break the for loop). Any suggestion how to get the PID of running for loop? and kill the same. Thanks in advance.

like image 828
BSalunke Avatar asked May 07 '12 09:05

BSalunke


2 Answers

You want to kill the running job. Press CtrlZ. Bash will show something like:

[1]+  Stopped                 vim $i

Use that number with kill to send the KILL signal:

kill -9 %1

and it should be killed afterwards:

[1]+  Killed                  vim $i
like image 151
eepp Avatar answered Sep 18 '22 13:09

eepp


This might also do the trick:

while true ; do killall vim ; done

You can abort this one with ^C as usual.

like image 29
Thomas Avatar answered Sep 18 '22 13:09

Thomas