Advertisement
littPekee

app_killer.sh

May 7th, 2024
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.52 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # Name of the app to monitor
  4. app_name="appname"
  5.  
  6. # Function that verifies if the app is running
  7. check_process() {
  8.     if pgrep -x "$app_name" > /dev/null
  9.     then
  10.         return 0
  11.     else
  12.         return 1
  13.     fi
  14. }
  15.  
  16. # Function to stop the app
  17. stop_process() {
  18.     pkill -x "$app_name"
  19.     echo "The process of $app_name was stopped"
  20. }
  21.  
  22. # Loop to monitor and stop the application
  23. while true
  24. do
  25.     if check_process
  26.     then
  27.         stop_process
  28.     fi
  29.     sleep 5  # Verify every 5 seconds
  30. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement