Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. # spawn.sh
  3.  
  4.  
  5. PIDS=$( pidof sh $0 )  # Process IDs of the various instances of this script.
  6. P_array=( $PIDS )     # Put them in an array (why?).
  7. echo $PIDS           # Show process IDs of parent and child processes.
  8. let "instances = ${#P_array[*]} - 1"  # Count elements, less 1.
  9.                                       # Why subtract 1?
  10. echo "$instances instance(s) of this script running."
  11. echo "[Hit Ctl-C to exit.]"; echo
  12.  
  13.  
  14. sleep 1              # Wait.
  15. sh $0                # Play it again, Sam.
  16.  
  17. exit 0               # Not necessary; script will never get to here.
  18.                      # Why not?