Created
May 21, 2016 08:22
-
-
Save spot62/7d14f5e2d4ca971c8c4697883581dacc to your computer and use it in GitHub Desktop.
Unix shell daemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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