How to stop a bash while loop running in the background?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
19
down vote

favorite
6












I started a while loop as follows:



while true; do command; sleep 180; done &


Notice the &.



I thought when I killed the terminal, this while loop would stop. But it is still going. It has been hours since I killed the terminal session.



How do I stop this while loop?







share|improve this question


























    up vote
    19
    down vote

    favorite
    6












    I started a while loop as follows:



    while true; do command; sleep 180; done &


    Notice the &.



    I thought when I killed the terminal, this while loop would stop. But it is still going. It has been hours since I killed the terminal session.



    How do I stop this while loop?







    share|improve this question
























      up vote
      19
      down vote

      favorite
      6









      up vote
      19
      down vote

      favorite
      6






      6





      I started a while loop as follows:



      while true; do command; sleep 180; done &


      Notice the &.



      I thought when I killed the terminal, this while loop would stop. But it is still going. It has been hours since I killed the terminal session.



      How do I stop this while loop?







      share|improve this question














      I started a while loop as follows:



      while true; do command; sleep 180; done &


      Notice the &.



      I thought when I killed the terminal, this while loop would stop. But it is still going. It has been hours since I killed the terminal session.



      How do I stop this while loop?









      share|improve this question













      share|improve this question




      share|improve this question








      edited May 9 at 22:31









      Monty Harder

      30316




      30316










      asked May 9 at 5:57









      Saqib Ali

      2981312




      2981312




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          33
          down vote



          accepted












          I started



          while true; do yad; sleep 60; done &


          and closed the terminal to test it, now I got the same problem.



          If you already closed the terminal you've started the loop in



          Let's get an overview of running processes with ps fjx, the last lines on my machine read



           2226 11606 11606 19337 ? -1 S 1000 0:00 _ /bin/bash
          11606 22485 11606 19337 ? -1 S 1000 0:00 | _ sleep 10
          2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
          9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad
          1 2215 2215 2215 ? -1 Ss 1000 0:00 /lib/systemd/systemd --user
          2215 2216 2215 2215 ? -1 S 1000 0:00 _ (sd-pam)


          You can see yad as a subprocess of /bin/bash, if I close yad it changes to sleep 60 in the output of ps. If the tree view is too confusing you can also search the output as follows1:



          ps fjx | grep "[y]ad" # or respectively
          ps fjx | grep "[s]leep 60"


          The output lines begin with two numbers, the first being the PPID, the process ID of the parent process and the second being the PID, the ID of the process itself. It's because of that 9411 appears in both rows here:




          2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
          9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad


          That's the bash subshell we want to kill and we just found out its PID, so now everything that remains is a simple



          kill 9411 # replace 9411 with the PID you found out!


          and the annoying subshell is gone for good.



          1: The notation as grep "[y]ad" instead of simply grep yad prevents the grep process itself from showing up in the results list.




          If you have the terminal still open



          bash provides the variable $!, which “expands to the process ID of the job most recently placed into the background”, so the following just kills the latest process in the background:



          kill $!


          If it's not the latest process, just can get a list of running jobs with the jobs builtin, example output:



          [1]- Running while true; do
          yad; sleep 60;
          done &
          [2]+ Stopped sleep 10


          There are two jobs in the job list, to kill one of them you can access it with the job number or the shortcuts %, %+ (“current job”) and %- (“previous job”), e.g. to kill the loop running in the background you could do



          kill %1 # or
          kill %-


          and to kill the suspended sleep 10 job:



          kill %2 # or
          kill %+ # or
          kill %





          share|improve this answer





























            up vote
            5
            down vote













            I need to note that when you close the terminal where you entered that command, the sub-command should've died along with it. Trying to reproduce this showed this behavior.



            Now, assuming that you indeed are in a situation where this didn't happen, one way to go about killing the program you left running in the background, which was caused by the & at the end of the command, is as follows:



            1. Open a new shell and run echo $$ to note your current PID (process ID), so that you don't kill your own session.

            2. Identify the PID of the program you think is still running; you can do this using the ps -ef | grep $SHELL command to find which programs are running a shell.

            3. Note the 2nd column from the left and note the numeric value that differs from your echo $$ result above; this is the PID you want to kill.

            4. Run the kill -SIGTERM <pid> command, where <pid> is the numeric value you identified in step #3

            5. Confirm the program is no longer running by repeating step #2

            You could also restart your session or your computer, but the above will allow you to avoid that.






            share|improve this answer


















            • 1




              You could also use top to kill the process by pressing k, then entering the PID, then pressing enter twice.
              – luk3yx
              May 9 at 6:19


















            up vote
            -1
            down vote













            The & will make the terminal create a new process and get your code to run inside it. So your code becomes independent from the terminal process. Even if you close the terminal the newly process in which your code is running won't stop. So either remove & or do ps -aux, locate your process and kill it kill (process id).






            share|improve this answer





























              up vote
              -3
              down vote













              Usually bg for background fg for foreground. If you use & symbol use fg it will show the current running program. Press Ctrl+C to kill.






              share|improve this answer
















              • 3




                Using bg/fg won't work once terminal is detached from bash. Would be unable to reattach using reptyr because bash has child processes (sleep).
                – xiota
                May 9 at 7:04










              • He closed terminal because he will kill that process. So next time he will use fg to close the program. Simple
                – Curious
                May 9 at 9:28










              • @Curious that's next time. But OP is asking about this time.
                – RonJohn
                May 9 at 22:35










              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "89"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );








               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1033866%2fhow-to-stop-a-bash-while-loop-running-in-the-background%23new-answer', 'question_page');

              );

              Post as a guest






























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              33
              down vote



              accepted












              I started



              while true; do yad; sleep 60; done &


              and closed the terminal to test it, now I got the same problem.



              If you already closed the terminal you've started the loop in



              Let's get an overview of running processes with ps fjx, the last lines on my machine read



               2226 11606 11606 19337 ? -1 S 1000 0:00 _ /bin/bash
              11606 22485 11606 19337 ? -1 S 1000 0:00 | _ sleep 10
              2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
              9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad
              1 2215 2215 2215 ? -1 Ss 1000 0:00 /lib/systemd/systemd --user
              2215 2216 2215 2215 ? -1 S 1000 0:00 _ (sd-pam)


              You can see yad as a subprocess of /bin/bash, if I close yad it changes to sleep 60 in the output of ps. If the tree view is too confusing you can also search the output as follows1:



              ps fjx | grep "[y]ad" # or respectively
              ps fjx | grep "[s]leep 60"


              The output lines begin with two numbers, the first being the PPID, the process ID of the parent process and the second being the PID, the ID of the process itself. It's because of that 9411 appears in both rows here:




              2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
              9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad


              That's the bash subshell we want to kill and we just found out its PID, so now everything that remains is a simple



              kill 9411 # replace 9411 with the PID you found out!


              and the annoying subshell is gone for good.



              1: The notation as grep "[y]ad" instead of simply grep yad prevents the grep process itself from showing up in the results list.




              If you have the terminal still open



              bash provides the variable $!, which “expands to the process ID of the job most recently placed into the background”, so the following just kills the latest process in the background:



              kill $!


              If it's not the latest process, just can get a list of running jobs with the jobs builtin, example output:



              [1]- Running while true; do
              yad; sleep 60;
              done &
              [2]+ Stopped sleep 10


              There are two jobs in the job list, to kill one of them you can access it with the job number or the shortcuts %, %+ (“current job”) and %- (“previous job”), e.g. to kill the loop running in the background you could do



              kill %1 # or
              kill %-


              and to kill the suspended sleep 10 job:



              kill %2 # or
              kill %+ # or
              kill %





              share|improve this answer


























                up vote
                33
                down vote



                accepted












                I started



                while true; do yad; sleep 60; done &


                and closed the terminal to test it, now I got the same problem.



                If you already closed the terminal you've started the loop in



                Let's get an overview of running processes with ps fjx, the last lines on my machine read



                 2226 11606 11606 19337 ? -1 S 1000 0:00 _ /bin/bash
                11606 22485 11606 19337 ? -1 S 1000 0:00 | _ sleep 10
                2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
                9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad
                1 2215 2215 2215 ? -1 Ss 1000 0:00 /lib/systemd/systemd --user
                2215 2216 2215 2215 ? -1 S 1000 0:00 _ (sd-pam)


                You can see yad as a subprocess of /bin/bash, if I close yad it changes to sleep 60 in the output of ps. If the tree view is too confusing you can also search the output as follows1:



                ps fjx | grep "[y]ad" # or respectively
                ps fjx | grep "[s]leep 60"


                The output lines begin with two numbers, the first being the PPID, the process ID of the parent process and the second being the PID, the ID of the process itself. It's because of that 9411 appears in both rows here:




                2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
                9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad


                That's the bash subshell we want to kill and we just found out its PID, so now everything that remains is a simple



                kill 9411 # replace 9411 with the PID you found out!


                and the annoying subshell is gone for good.



                1: The notation as grep "[y]ad" instead of simply grep yad prevents the grep process itself from showing up in the results list.




                If you have the terminal still open



                bash provides the variable $!, which “expands to the process ID of the job most recently placed into the background”, so the following just kills the latest process in the background:



                kill $!


                If it's not the latest process, just can get a list of running jobs with the jobs builtin, example output:



                [1]- Running while true; do
                yad; sleep 60;
                done &
                [2]+ Stopped sleep 10


                There are two jobs in the job list, to kill one of them you can access it with the job number or the shortcuts %, %+ (“current job”) and %- (“previous job”), e.g. to kill the loop running in the background you could do



                kill %1 # or
                kill %-


                and to kill the suspended sleep 10 job:



                kill %2 # or
                kill %+ # or
                kill %





                share|improve this answer
























                  up vote
                  33
                  down vote



                  accepted







                  up vote
                  33
                  down vote



                  accepted








                  I started



                  while true; do yad; sleep 60; done &


                  and closed the terminal to test it, now I got the same problem.



                  If you already closed the terminal you've started the loop in



                  Let's get an overview of running processes with ps fjx, the last lines on my machine read



                   2226 11606 11606 19337 ? -1 S 1000 0:00 _ /bin/bash
                  11606 22485 11606 19337 ? -1 S 1000 0:00 | _ sleep 10
                  2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
                  9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad
                  1 2215 2215 2215 ? -1 Ss 1000 0:00 /lib/systemd/systemd --user
                  2215 2216 2215 2215 ? -1 S 1000 0:00 _ (sd-pam)


                  You can see yad as a subprocess of /bin/bash, if I close yad it changes to sleep 60 in the output of ps. If the tree view is too confusing you can also search the output as follows1:



                  ps fjx | grep "[y]ad" # or respectively
                  ps fjx | grep "[s]leep 60"


                  The output lines begin with two numbers, the first being the PPID, the process ID of the parent process and the second being the PID, the ID of the process itself. It's because of that 9411 appears in both rows here:




                  2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
                  9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad


                  That's the bash subshell we want to kill and we just found out its PID, so now everything that remains is a simple



                  kill 9411 # replace 9411 with the PID you found out!


                  and the annoying subshell is gone for good.



                  1: The notation as grep "[y]ad" instead of simply grep yad prevents the grep process itself from showing up in the results list.




                  If you have the terminal still open



                  bash provides the variable $!, which “expands to the process ID of the job most recently placed into the background”, so the following just kills the latest process in the background:



                  kill $!


                  If it's not the latest process, just can get a list of running jobs with the jobs builtin, example output:



                  [1]- Running while true; do
                  yad; sleep 60;
                  done &
                  [2]+ Stopped sleep 10


                  There are two jobs in the job list, to kill one of them you can access it with the job number or the shortcuts %, %+ (“current job”) and %- (“previous job”), e.g. to kill the loop running in the background you could do



                  kill %1 # or
                  kill %-


                  and to kill the suspended sleep 10 job:



                  kill %2 # or
                  kill %+ # or
                  kill %





                  share|improve this answer
















                  I started



                  while true; do yad; sleep 60; done &


                  and closed the terminal to test it, now I got the same problem.



                  If you already closed the terminal you've started the loop in



                  Let's get an overview of running processes with ps fjx, the last lines on my machine read



                   2226 11606 11606 19337 ? -1 S 1000 0:00 _ /bin/bash
                  11606 22485 11606 19337 ? -1 S 1000 0:00 | _ sleep 10
                  2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
                  9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad
                  1 2215 2215 2215 ? -1 Ss 1000 0:00 /lib/systemd/systemd --user
                  2215 2216 2215 2215 ? -1 S 1000 0:00 _ (sd-pam)


                  You can see yad as a subprocess of /bin/bash, if I close yad it changes to sleep 60 in the output of ps. If the tree view is too confusing you can also search the output as follows1:



                  ps fjx | grep "[y]ad" # or respectively
                  ps fjx | grep "[s]leep 60"


                  The output lines begin with two numbers, the first being the PPID, the process ID of the parent process and the second being the PID, the ID of the process itself. It's because of that 9411 appears in both rows here:




                  2226 9411 9411 8383 ? -1 S 1000 0:00 _ /bin/bash
                  9411 17674 9411 8383 ? -1 Sl 1000 0:00 _ yad


                  That's the bash subshell we want to kill and we just found out its PID, so now everything that remains is a simple



                  kill 9411 # replace 9411 with the PID you found out!


                  and the annoying subshell is gone for good.



                  1: The notation as grep "[y]ad" instead of simply grep yad prevents the grep process itself from showing up in the results list.




                  If you have the terminal still open



                  bash provides the variable $!, which “expands to the process ID of the job most recently placed into the background”, so the following just kills the latest process in the background:



                  kill $!


                  If it's not the latest process, just can get a list of running jobs with the jobs builtin, example output:



                  [1]- Running while true; do
                  yad; sleep 60;
                  done &
                  [2]+ Stopped sleep 10


                  There are two jobs in the job list, to kill one of them you can access it with the job number or the shortcuts %, %+ (“current job”) and %- (“previous job”), e.g. to kill the loop running in the background you could do



                  kill %1 # or
                  kill %-


                  and to kill the suspended sleep 10 job:



                  kill %2 # or
                  kill %+ # or
                  kill %






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 9 at 13:31

























                  answered May 9 at 6:47









                  dessert

                  19.6k55594




                  19.6k55594






















                      up vote
                      5
                      down vote













                      I need to note that when you close the terminal where you entered that command, the sub-command should've died along with it. Trying to reproduce this showed this behavior.



                      Now, assuming that you indeed are in a situation where this didn't happen, one way to go about killing the program you left running in the background, which was caused by the & at the end of the command, is as follows:



                      1. Open a new shell and run echo $$ to note your current PID (process ID), so that you don't kill your own session.

                      2. Identify the PID of the program you think is still running; you can do this using the ps -ef | grep $SHELL command to find which programs are running a shell.

                      3. Note the 2nd column from the left and note the numeric value that differs from your echo $$ result above; this is the PID you want to kill.

                      4. Run the kill -SIGTERM <pid> command, where <pid> is the numeric value you identified in step #3

                      5. Confirm the program is no longer running by repeating step #2

                      You could also restart your session or your computer, but the above will allow you to avoid that.






                      share|improve this answer


















                      • 1




                        You could also use top to kill the process by pressing k, then entering the PID, then pressing enter twice.
                        – luk3yx
                        May 9 at 6:19















                      up vote
                      5
                      down vote













                      I need to note that when you close the terminal where you entered that command, the sub-command should've died along with it. Trying to reproduce this showed this behavior.



                      Now, assuming that you indeed are in a situation where this didn't happen, one way to go about killing the program you left running in the background, which was caused by the & at the end of the command, is as follows:



                      1. Open a new shell and run echo $$ to note your current PID (process ID), so that you don't kill your own session.

                      2. Identify the PID of the program you think is still running; you can do this using the ps -ef | grep $SHELL command to find which programs are running a shell.

                      3. Note the 2nd column from the left and note the numeric value that differs from your echo $$ result above; this is the PID you want to kill.

                      4. Run the kill -SIGTERM <pid> command, where <pid> is the numeric value you identified in step #3

                      5. Confirm the program is no longer running by repeating step #2

                      You could also restart your session or your computer, but the above will allow you to avoid that.






                      share|improve this answer


















                      • 1




                        You could also use top to kill the process by pressing k, then entering the PID, then pressing enter twice.
                        – luk3yx
                        May 9 at 6:19













                      up vote
                      5
                      down vote










                      up vote
                      5
                      down vote









                      I need to note that when you close the terminal where you entered that command, the sub-command should've died along with it. Trying to reproduce this showed this behavior.



                      Now, assuming that you indeed are in a situation where this didn't happen, one way to go about killing the program you left running in the background, which was caused by the & at the end of the command, is as follows:



                      1. Open a new shell and run echo $$ to note your current PID (process ID), so that you don't kill your own session.

                      2. Identify the PID of the program you think is still running; you can do this using the ps -ef | grep $SHELL command to find which programs are running a shell.

                      3. Note the 2nd column from the left and note the numeric value that differs from your echo $$ result above; this is the PID you want to kill.

                      4. Run the kill -SIGTERM <pid> command, where <pid> is the numeric value you identified in step #3

                      5. Confirm the program is no longer running by repeating step #2

                      You could also restart your session or your computer, but the above will allow you to avoid that.






                      share|improve this answer














                      I need to note that when you close the terminal where you entered that command, the sub-command should've died along with it. Trying to reproduce this showed this behavior.



                      Now, assuming that you indeed are in a situation where this didn't happen, one way to go about killing the program you left running in the background, which was caused by the & at the end of the command, is as follows:



                      1. Open a new shell and run echo $$ to note your current PID (process ID), so that you don't kill your own session.

                      2. Identify the PID of the program you think is still running; you can do this using the ps -ef | grep $SHELL command to find which programs are running a shell.

                      3. Note the 2nd column from the left and note the numeric value that differs from your echo $$ result above; this is the PID you want to kill.

                      4. Run the kill -SIGTERM <pid> command, where <pid> is the numeric value you identified in step #3

                      5. Confirm the program is no longer running by repeating step #2

                      You could also restart your session or your computer, but the above will allow you to avoid that.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 9 at 6:39

























                      answered May 9 at 6:05









                      code_dredd

                      4991413




                      4991413







                      • 1




                        You could also use top to kill the process by pressing k, then entering the PID, then pressing enter twice.
                        – luk3yx
                        May 9 at 6:19













                      • 1




                        You could also use top to kill the process by pressing k, then entering the PID, then pressing enter twice.
                        – luk3yx
                        May 9 at 6:19








                      1




                      1




                      You could also use top to kill the process by pressing k, then entering the PID, then pressing enter twice.
                      – luk3yx
                      May 9 at 6:19





                      You could also use top to kill the process by pressing k, then entering the PID, then pressing enter twice.
                      – luk3yx
                      May 9 at 6:19











                      up vote
                      -1
                      down vote













                      The & will make the terminal create a new process and get your code to run inside it. So your code becomes independent from the terminal process. Even if you close the terminal the newly process in which your code is running won't stop. So either remove & or do ps -aux, locate your process and kill it kill (process id).






                      share|improve this answer


























                        up vote
                        -1
                        down vote













                        The & will make the terminal create a new process and get your code to run inside it. So your code becomes independent from the terminal process. Even if you close the terminal the newly process in which your code is running won't stop. So either remove & or do ps -aux, locate your process and kill it kill (process id).






                        share|improve this answer
























                          up vote
                          -1
                          down vote










                          up vote
                          -1
                          down vote









                          The & will make the terminal create a new process and get your code to run inside it. So your code becomes independent from the terminal process. Even if you close the terminal the newly process in which your code is running won't stop. So either remove & or do ps -aux, locate your process and kill it kill (process id).






                          share|improve this answer














                          The & will make the terminal create a new process and get your code to run inside it. So your code becomes independent from the terminal process. Even if you close the terminal the newly process in which your code is running won't stop. So either remove & or do ps -aux, locate your process and kill it kill (process id).







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited May 9 at 22:42









                          ubashu

                          2,23721736




                          2,23721736










                          answered May 9 at 21:56









                          Dr4ke the b4dass

                          11




                          11




















                              up vote
                              -3
                              down vote













                              Usually bg for background fg for foreground. If you use & symbol use fg it will show the current running program. Press Ctrl+C to kill.






                              share|improve this answer
















                              • 3




                                Using bg/fg won't work once terminal is detached from bash. Would be unable to reattach using reptyr because bash has child processes (sleep).
                                – xiota
                                May 9 at 7:04










                              • He closed terminal because he will kill that process. So next time he will use fg to close the program. Simple
                                – Curious
                                May 9 at 9:28










                              • @Curious that's next time. But OP is asking about this time.
                                – RonJohn
                                May 9 at 22:35














                              up vote
                              -3
                              down vote













                              Usually bg for background fg for foreground. If you use & symbol use fg it will show the current running program. Press Ctrl+C to kill.






                              share|improve this answer
















                              • 3




                                Using bg/fg won't work once terminal is detached from bash. Would be unable to reattach using reptyr because bash has child processes (sleep).
                                – xiota
                                May 9 at 7:04










                              • He closed terminal because he will kill that process. So next time he will use fg to close the program. Simple
                                – Curious
                                May 9 at 9:28










                              • @Curious that's next time. But OP is asking about this time.
                                – RonJohn
                                May 9 at 22:35












                              up vote
                              -3
                              down vote










                              up vote
                              -3
                              down vote









                              Usually bg for background fg for foreground. If you use & symbol use fg it will show the current running program. Press Ctrl+C to kill.






                              share|improve this answer












                              Usually bg for background fg for foreground. If you use & symbol use fg it will show the current running program. Press Ctrl+C to kill.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered May 9 at 6:54









                              Curious

                              53




                              53







                              • 3




                                Using bg/fg won't work once terminal is detached from bash. Would be unable to reattach using reptyr because bash has child processes (sleep).
                                – xiota
                                May 9 at 7:04










                              • He closed terminal because he will kill that process. So next time he will use fg to close the program. Simple
                                – Curious
                                May 9 at 9:28










                              • @Curious that's next time. But OP is asking about this time.
                                – RonJohn
                                May 9 at 22:35












                              • 3




                                Using bg/fg won't work once terminal is detached from bash. Would be unable to reattach using reptyr because bash has child processes (sleep).
                                – xiota
                                May 9 at 7:04










                              • He closed terminal because he will kill that process. So next time he will use fg to close the program. Simple
                                – Curious
                                May 9 at 9:28










                              • @Curious that's next time. But OP is asking about this time.
                                – RonJohn
                                May 9 at 22:35







                              3




                              3




                              Using bg/fg won't work once terminal is detached from bash. Would be unable to reattach using reptyr because bash has child processes (sleep).
                              – xiota
                              May 9 at 7:04




                              Using bg/fg won't work once terminal is detached from bash. Would be unable to reattach using reptyr because bash has child processes (sleep).
                              – xiota
                              May 9 at 7:04












                              He closed terminal because he will kill that process. So next time he will use fg to close the program. Simple
                              – Curious
                              May 9 at 9:28




                              He closed terminal because he will kill that process. So next time he will use fg to close the program. Simple
                              – Curious
                              May 9 at 9:28












                              @Curious that's next time. But OP is asking about this time.
                              – RonJohn
                              May 9 at 22:35




                              @Curious that's next time. But OP is asking about this time.
                              – RonJohn
                              May 9 at 22:35












                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1033866%2fhow-to-stop-a-bash-while-loop-running-in-the-background%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              pylint3 and pip3 broken

                              Missing snmpget and snmpwalk

                              How to enroll fingerprints to Ubuntu 17.10 with VFS491