How to terminate while loop.
Hi
I started a while loop directly from terminal to read a file line by line and to run a command on each line. Post running the command I realized to modify the command and tried to stop the loop by using CTRL+C but it didn't stop. I closed that terminal directly but loop is still running. I also tried to KILL the process but it is getting started automatically with a new PID. Please suggest to stop this loop. Thanks. |
kill the parent process, probably a bash shell.
|
How did you start the while loop?
|
What I did is I searched the PID for the command running on each line and killed the same. Please suggest, how to kill parent process.
|
while read line
do ldapsearch $line done < filename |
pstree -p will show the parents with their PIDs
|
Use the pstree command to find the parent process, e.g.
Code:
pstree -p username Edit: Beaten by catkin for a bunch of seconds! ;) Hi Charles! :) |
Quote:
EDIT: and doesn't exit |
Quote:
|
Quote:
We keep doing that, one way round or the other |
Hi colucix
I killed the parent process but process is still running with a new parent ID. Also tried to move the filename. |
Try killing the parent's parent
|
Killing the parent process, didn't help.
|
Assuming you are not logged on as root, try killing the parent's parent and, if that doesn't work, the parent's parent's parent
|
Quote:
Quote:
If it is not a live system, then shutdown -h now or shutdown -g0 ` OK. |
Quote:
Kevin Barry |
Check out these new functions that I just made. They might be helpful.
Code:
#!/bin/bash |
Quote:
Apart from the "hard drive problem" (which I don't understand but would like to know more about), the bash command shown would not do any of those so it would have to be ldapsearch command ... yes? |
Quote:
Quote:
Kevin Barry |
Sometimes CTRL-C isn’t working, maybe because it’s trapped or whatever. But a CTRL-Z succeeds and than you can either kill %1 of bg %1 at your convenience.
|
Quote:
|
I never star a loop from terminal. But, when I run C++ programs and a loop is infinite (the condition to stop the loop is never true), and for other blocking situations I use ctrl/z.
|
Now loop has been completed and terminated automatically. Thanks anyway.
|
All times are GMT -5. The time now is 11:07 PM. |