Does anyone know how to write a daemon? I want to write a daemon which executes a script to move a file from one particular directory to another.
Isn't running a cron job every 5 minutes considered a bad practice?
yogsma
2010-10-06 18:33:36
No, why would it be bad practice? In many cases, it would be preferable to a long-running daemon. I have many cron jobs that run every minute - they're very short jobs (runtimes in the sub-second range), but there's nothing wrong with doing that. The only thing you have to be careful with is to make sure that your cron job doesn't last longer than the frequency you have it set to run.
ErikA
2010-10-06 18:36:26
What happens in the case of system failure?
yogsma
2010-10-06 18:46:04
"System failure"? Like the server crashes or hardware breaks? In that case, the cron job will obviously not run, but neither would the daemon you proposed.
ErikA
2010-10-06 18:49:43
+1, Why reinvent the wheel when a quick script and cron will do it?
Chris S
2010-10-06 20:13:04
@ErikA, @yogsma - in the "case of system failure", your crontab is still intact on reboot, and will resume.
warren
2010-10-07 00:19:25
+1
A:
the easiest way is to use nohup.
nohup your_command.sh &
And your_command run as a daemon.
yogsototh
2010-10-06 21:42:27