
Untitled
By: a guest on
Jul 17th, 2012 | syntax:
None | size: 0.61 KB | hits: 11 | expires: Never
#!/bin/bash
# spawn.sh
PIDS=$( pidof sh $0 ) # Process IDs of the various instances of this script.
P_array=( $PIDS ) # Put them in an array (why?).
echo $PIDS # Show process IDs of parent and child processes.
let "instances = ${#P_array[*]} - 1" # Count elements, less 1.
# Why subtract 1?
echo "$instances instance(s) of this script running."
echo "[Hit Ctl-C to exit.]"; echo
sleep 1 # Wait.
sh $0 # Play it again, Sam.
exit 0 # Not necessary; script will never get to here.
# Why not?