tags:

views:

69

answers:

5

I'm wondering if there is a better way to make a daemon that waits for something using only sh than:

#! /bin/sh
trap processUserSig SIGUSR1
processUserSig() {
  echo "doing stuff"
}

while true; do
  sleep 1000
done

In particular, I'm wondering if there's any way to get rid of the loop and still have the thing listen for the signals.

A: 

ref 1

org.life.java
A: 

Have a look at the daemon tool from the libslack package:

http://ingvar.blog.linpro.no/2009/05/18/todays-sysadmin-tip-using-libslack-daemon-to-daemonize-a-script/

On Mac OS X use a launchd script for shell daemon.

timo
A: 

Use your system's daemon facility, such as start-stop-daemon.

Otherwise, yes, there has to be a loop somewhere.

Dennis Williamson
A: 

try executing using & if you save this file as program.sh

you can use

$./program.sh &
jasimmk
+1  A: 
# double background your script to have it detach from the tty
# cf. http://www.linux-mag.com/id/5981 
(./program.sh &) & 
carlo