Advertisement
julenvitoria

k

Apr 28th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | None | 0 0
  1. #!/bin/bash
  2. # Shutdown Script Emulator Sceleton
  3. # by cyperghost for retropie
  4.  
  5.  
  6. # --------------------------
  7. # Initial release: ??? Don't know January 2018?
  8. # 04/19/18 Release in RetroPie forums
  9. # 04/20/18 julenvitoria introduced kill -9 signal for emulators
  10.  
  11. # This function is called still all childPIDs are found
  12. function getcpid() {
  13. local cpids="$(pgrep -P $1)"
  14.     for cpid in $cpids;
  15.     do
  16.         pidarray+=($cpid)
  17.         getcpid $cpid
  18.     done
  19. }
  20.  
  21. # Abolish sleep timer! This one is much better!
  22. function smart_wait() {
  23.     local PID=$1
  24.     while [[ -e /proc/$PID ]]
  25.     do
  26.         sleep 0.05
  27.     done
  28. }
  29.  
  30. # Our entrypoint! RUNCOMMAND is alpha, emulator is OMEGA
  31. motherpid="$(pgrep -f -n runcommand.sh)"
  32.  
  33. # if there is no runcommand.sh running then exit
  34. [ "$motherpid" ] && getcpid $motherpid || exit
  35.  
  36. # Reverse array and do your TERM job
  37. for ((z=${#pidarray[*]}-1; z>-1; z--)); do
  38.     echo "Terminate PID ${pidarray[z]}"
  39.     kill -9 ${pidarray[z]}
  40.     smart_wait ${pidarray[z]}
  41. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement