Skip to content

Instantly share code, notes, and snippets.

@ycombinator
Created July 25, 2019 19:44
Show Gist options
  • Save ycombinator/e645078f72ad6a180c32af818828a9df to your computer and use it in GitHub Desktop.
Save ycombinator/e645078f72ad6a180c32af818828a9df to your computer and use it in GitHub Desktop.
Child care
#!/bin/bash
CHILD_PIDFILE=$PWD/child.pid
# Clean up old child, if any
if [ -f $CHILD_PIDFILE ]; then
OLD_CHILD_PID=$(cat $CHILD_PIDFILE)
ps $OLD_CHILD_PID >/dev/null
if [ $? -eq 0 ]; then
kill -9 $OLD_CHILD_PID
fi
rm $CHILD_PIDFILE
fi
# Spawn child
nc -l -p 2000 &
CHILD_PID=$!
echo $CHILD_PID > $CHILD_PIDFILE
# Sleep to give us some time to poke around
sleep 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment