Shell script example to stop execution of all processes with a certain UID? [duplicate]

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











up vote
0
down vote

favorite













This question already has an answer here:



  • How do I kill all a user's processes using their UID

    5 answers



I'm new to scripting and I can't seem to find any examples on the internet for this particular task. I'd much appreciate a bit of help.







share|improve this question











marked as duplicate by Romeo Ninov, ilkkachu, G-Man, Jeff Schaller, sourcejedi May 27 at 19:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Try for i in $(pgrep -U $UID); do kill -9 $i; done or pkill -U $UID whichever seems suitable, replace $UID with the required UID or just assign it a value beforehand.
    – Kunal Gupta
    May 27 at 8:06











  • All solutions will require CAP_KILL (permission to kill any process), or to be root (root has this permission).
    – ctrl-alt-delor
    May 27 at 11:36














up vote
0
down vote

favorite













This question already has an answer here:



  • How do I kill all a user's processes using their UID

    5 answers



I'm new to scripting and I can't seem to find any examples on the internet for this particular task. I'd much appreciate a bit of help.







share|improve this question











marked as duplicate by Romeo Ninov, ilkkachu, G-Man, Jeff Schaller, sourcejedi May 27 at 19:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Try for i in $(pgrep -U $UID); do kill -9 $i; done or pkill -U $UID whichever seems suitable, replace $UID with the required UID or just assign it a value beforehand.
    – Kunal Gupta
    May 27 at 8:06











  • All solutions will require CAP_KILL (permission to kill any process), or to be root (root has this permission).
    – ctrl-alt-delor
    May 27 at 11:36












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • How do I kill all a user's processes using their UID

    5 answers



I'm new to scripting and I can't seem to find any examples on the internet for this particular task. I'd much appreciate a bit of help.







share|improve this question












This question already has an answer here:



  • How do I kill all a user's processes using their UID

    5 answers



I'm new to scripting and I can't seem to find any examples on the internet for this particular task. I'd much appreciate a bit of help.





This question already has an answer here:



  • How do I kill all a user's processes using their UID

    5 answers









share|improve this question










share|improve this question




share|improve this question









asked May 27 at 8:01









Amelie

1




1




marked as duplicate by Romeo Ninov, ilkkachu, G-Man, Jeff Schaller, sourcejedi May 27 at 19:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Romeo Ninov, ilkkachu, G-Man, Jeff Schaller, sourcejedi May 27 at 19:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • Try for i in $(pgrep -U $UID); do kill -9 $i; done or pkill -U $UID whichever seems suitable, replace $UID with the required UID or just assign it a value beforehand.
    – Kunal Gupta
    May 27 at 8:06











  • All solutions will require CAP_KILL (permission to kill any process), or to be root (root has this permission).
    – ctrl-alt-delor
    May 27 at 11:36
















  • Try for i in $(pgrep -U $UID); do kill -9 $i; done or pkill -U $UID whichever seems suitable, replace $UID with the required UID or just assign it a value beforehand.
    – Kunal Gupta
    May 27 at 8:06











  • All solutions will require CAP_KILL (permission to kill any process), or to be root (root has this permission).
    – ctrl-alt-delor
    May 27 at 11:36















Try for i in $(pgrep -U $UID); do kill -9 $i; done or pkill -U $UID whichever seems suitable, replace $UID with the required UID or just assign it a value beforehand.
– Kunal Gupta
May 27 at 8:06





Try for i in $(pgrep -U $UID); do kill -9 $i; done or pkill -U $UID whichever seems suitable, replace $UID with the required UID or just assign it a value beforehand.
– Kunal Gupta
May 27 at 8:06













All solutions will require CAP_KILL (permission to kill any process), or to be root (root has this permission).
– ctrl-alt-delor
May 27 at 11:36




All solutions will require CAP_KILL (permission to kill any process), or to be root (root has this permission).
– ctrl-alt-delor
May 27 at 11:36










3 Answers
3






active

oldest

votes

















up vote
2
down vote













You can do this either via:



for i in $(pgrep -U $UID_OF_ANOTHER_USER); do kill -9 $i; done


OR



pkill -U $UID_OF_ANOTHER_USER


You can use the first one to do something more other than just killing those processes, like listing all of them while killing.






share|improve this answer



















  • 1




    As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing.
    – ctrl-alt-delor
    May 27 at 11:34

















up vote
1
down vote













Here is a simple solution, that will work if you are root.



su $uid -c kill SIGSTOP -1



Explanation: become that user, and kill everything that you can.




All solutions will require CAP_KILL (permission to kill any process), or to be traditional root (root has this permission), and permission (capability to change its own uid), as used by this solution.



Note I sent sigstop, this will pause the process (as asked for ☺). Chose the signal that you want. Use sigkill as last resort.






share|improve this answer






























    up vote
    0
    down vote













    killall -u $user -STOP


    This is safe if run as another user and (for other signals) if no parent process belongs to the affected user.



    ctrl-alt-delor's solution is probably better (safer). This one has the advantage of giving you a real exit code, though. The other one probably does not as both su and kill get killed themselves.






    share|improve this answer




























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      You can do this either via:



      for i in $(pgrep -U $UID_OF_ANOTHER_USER); do kill -9 $i; done


      OR



      pkill -U $UID_OF_ANOTHER_USER


      You can use the first one to do something more other than just killing those processes, like listing all of them while killing.






      share|improve this answer



















      • 1




        As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing.
        – ctrl-alt-delor
        May 27 at 11:34














      up vote
      2
      down vote













      You can do this either via:



      for i in $(pgrep -U $UID_OF_ANOTHER_USER); do kill -9 $i; done


      OR



      pkill -U $UID_OF_ANOTHER_USER


      You can use the first one to do something more other than just killing those processes, like listing all of them while killing.






      share|improve this answer



















      • 1




        As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing.
        – ctrl-alt-delor
        May 27 at 11:34












      up vote
      2
      down vote










      up vote
      2
      down vote









      You can do this either via:



      for i in $(pgrep -U $UID_OF_ANOTHER_USER); do kill -9 $i; done


      OR



      pkill -U $UID_OF_ANOTHER_USER


      You can use the first one to do something more other than just killing those processes, like listing all of them while killing.






      share|improve this answer















      You can do this either via:



      for i in $(pgrep -U $UID_OF_ANOTHER_USER); do kill -9 $i; done


      OR



      pkill -U $UID_OF_ANOTHER_USER


      You can use the first one to do something more other than just killing those processes, like listing all of them while killing.







      share|improve this answer















      share|improve this answer



      share|improve this answer








      edited May 27 at 14:13


























      answered May 27 at 8:11









      Kunal Gupta

      1756




      1756







      • 1




        As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing.
        – ctrl-alt-delor
        May 27 at 11:34












      • 1




        As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing.
        – ctrl-alt-delor
        May 27 at 11:34







      1




      1




      As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing.
      – ctrl-alt-delor
      May 27 at 11:34




      As $UID is the user id of the current user. This will kill your own processes. In addition, it may kill itself before finishing.
      – ctrl-alt-delor
      May 27 at 11:34












      up vote
      1
      down vote













      Here is a simple solution, that will work if you are root.



      su $uid -c kill SIGSTOP -1



      Explanation: become that user, and kill everything that you can.




      All solutions will require CAP_KILL (permission to kill any process), or to be traditional root (root has this permission), and permission (capability to change its own uid), as used by this solution.



      Note I sent sigstop, this will pause the process (as asked for ☺). Chose the signal that you want. Use sigkill as last resort.






      share|improve this answer



























        up vote
        1
        down vote













        Here is a simple solution, that will work if you are root.



        su $uid -c kill SIGSTOP -1



        Explanation: become that user, and kill everything that you can.




        All solutions will require CAP_KILL (permission to kill any process), or to be traditional root (root has this permission), and permission (capability to change its own uid), as used by this solution.



        Note I sent sigstop, this will pause the process (as asked for ☺). Chose the signal that you want. Use sigkill as last resort.






        share|improve this answer

























          up vote
          1
          down vote










          up vote
          1
          down vote









          Here is a simple solution, that will work if you are root.



          su $uid -c kill SIGSTOP -1



          Explanation: become that user, and kill everything that you can.




          All solutions will require CAP_KILL (permission to kill any process), or to be traditional root (root has this permission), and permission (capability to change its own uid), as used by this solution.



          Note I sent sigstop, this will pause the process (as asked for ☺). Chose the signal that you want. Use sigkill as last resort.






          share|improve this answer















          Here is a simple solution, that will work if you are root.



          su $uid -c kill SIGSTOP -1



          Explanation: become that user, and kill everything that you can.




          All solutions will require CAP_KILL (permission to kill any process), or to be traditional root (root has this permission), and permission (capability to change its own uid), as used by this solution.



          Note I sent sigstop, this will pause the process (as asked for ☺). Chose the signal that you want. Use sigkill as last resort.







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited May 27 at 11:36


























          answered May 27 at 11:31









          ctrl-alt-delor

          8,75831947




          8,75831947




















              up vote
              0
              down vote













              killall -u $user -STOP


              This is safe if run as another user and (for other signals) if no parent process belongs to the affected user.



              ctrl-alt-delor's solution is probably better (safer). This one has the advantage of giving you a real exit code, though. The other one probably does not as both su and kill get killed themselves.






              share|improve this answer

























                up vote
                0
                down vote













                killall -u $user -STOP


                This is safe if run as another user and (for other signals) if no parent process belongs to the affected user.



                ctrl-alt-delor's solution is probably better (safer). This one has the advantage of giving you a real exit code, though. The other one probably does not as both su and kill get killed themselves.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  killall -u $user -STOP


                  This is safe if run as another user and (for other signals) if no parent process belongs to the affected user.



                  ctrl-alt-delor's solution is probably better (safer). This one has the advantage of giving you a real exit code, though. The other one probably does not as both su and kill get killed themselves.






                  share|improve this answer













                  killall -u $user -STOP


                  This is safe if run as another user and (for other signals) if no parent process belongs to the affected user.



                  ctrl-alt-delor's solution is probably better (safer). This one has the advantage of giving you a real exit code, though. The other one probably does not as both su and kill get killed themselves.







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered May 27 at 13:37









                  Hauke Laging

                  53.1k1282130




                  53.1k1282130












                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?