Skip to content

Instantly share code, notes, and snippets.

@spot62
Created May 21, 2016 08:22
Show Gist options
  • Save spot62/7d14f5e2d4ca971c8c4697883581dacc to your computer and use it in GitHub Desktop.
Save spot62/7d14f5e2d4ca971c8c4697883581dacc to your computer and use it in GitHub Desktop.
Unix shell daemon
#!/bin/sh
#1. сhange CWD to /
cd /
#2. disconnect from current terminal
exec >/dev/null
exec 2>/dev/null
#3. forked and leave in background
(
#4. SIGTERM ignoring
trap "" TERM
#5. some action
while true
do
date >> /tmp/test
sleep 10
done
) > /dev/null 2>&1 &
#the child remains in the background
#the parent process is finished
echo "Parent exit" >> /tmp/test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment