LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to terminate while loop. (https://www.linuxquestions.org/questions/programming-9/how-to-terminate-while-loop-937229/)

satishchahar 03-30-2012 03:31 AM

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.

acid_kewpie 03-30-2012 03:37 AM

kill the parent process, probably a bash shell.

catkin 03-30-2012 03:51 AM

How did you start the while loop?

satishchahar 03-30-2012 03:54 AM

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.

satishchahar 03-30-2012 03:55 AM

while read line
do
ldapsearch $line
done < filename

catkin 03-30-2012 03:57 AM

pstree -p will show the parents with their PIDs

colucix 03-30-2012 03:58 AM

Use the pstree command to find the parent process, e.g.
Code:

pstree -p username
specifying your username to reduce the output.

Edit: Beaten by catkin for a bunch of seconds! ;)



Hi Charles! :)

catkin 03-30-2012 03:59 AM

Quote:

Originally Posted by satishchahar (Post 4640451)
while read line
do
ldapsearch $line
done < filename

It's not obvious why that doesn't respond to multiple Ctrl+C signals, unless the ldapsearch command is programmed to ignore SIGINT.

EDIT: and doesn't exit

colucix 03-30-2012 04:00 AM

Quote:

Originally Posted by satishchahar (Post 4640451)
while read line
do
ldapsearch $line
done < filename

Have you tried to rename or move filename?

catkin 03-30-2012 04:01 AM

Quote:

Originally Posted by colucix (Post 4640454)
Edit: Beaten by catkin for a bunch of seconds! ;)

Hi Charles! :)

Hi colucix :)

We keep doing that, one way round or the other

satishchahar 03-30-2012 04:06 AM

Hi colucix

I killed the parent process but process is still running with a new parent ID.
Also tried to move the filename.

catkin 03-30-2012 04:08 AM

Try killing the parent's parent

satishchahar 03-30-2012 04:30 AM

Killing the parent process, didn't help.

catkin 03-30-2012 05:11 AM

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

AnanthaP 03-30-2012 07:48 AM

Quote:

.. terminal to read a file line by line and to run a command on each line. P ..
Also
Quote:

I also tried to KILL the process but it is getting started automatically with a new PID
Could we see the culprit script?

If it is not a live system, then shutdown -h now or shutdown -g0
`

OK.


All times are GMT -5. The time now is 09:03 AM.