You are not logged in.
Pages: 1
Hi everyone.
I have made a script to keep a mirror of a local folder to an ftp. It works, but now I want it to run as a daemon, in the background.
Question is, how do I do that? How do I send a process to the background?
I'm looking to putting it in /etc/rc.d/ ...
Thanks in advance.
Offline
Take a look at some of the other daemons in /etc/rc.d for a template.
Specifically to start a script in the background, append a & to the line. For example:
$ firefox &
will start firefox in the background and allow you to type new commands in the terminal. You can also press CTRL-Z while a program is running and then type 'bg' to send the task to the background. To get a listing of currently running backgrounded programs, type 'jobs'
Dusty
Offline
"In the background" is a funny expression. The way I see it, everything runs in the background, and some programs are used to get some insight about what's going on in the background (shells and X clients). I wish more people saw things this way...
Anyway, you can write a little file in /etc/rc.d that will call your script (like Dusty said, follow the templates). It will be run headless, "in the background," upon boot (if you put the name of that little file in your DAEMONS array in /etc/rc.conf), or you can start in manually by calling
/etc/rc.d/$your_little_file start
.
Take a look at /etc/rc.multi (I think that's what it's called... can't check right now) to understand what's going on. (It's one of those executable files in /etc, and it has 'multi' in its name. It's the startup script responsible for launching what's given in the DAEMONS array)
Offline
Ok, but that "background" is a little different...
The way the daemons under /etc/rc.d are started is a little different....
They call processes that are daemons by themselves... If I call the script normally, the caller will wait for the script to finish and return something.
On the other hand, if I call it with &, it is supposed to die when the caller finishes, or sometime later, isn't it, because it's a child process?
should i use nohup?
Last edited by nDray (2008-03-05 21:13:48)
Offline
Wow, T-Dawg is back! Beers all round!
Dusty
Offline
who?
mwuhahahah....
Offline
wot? I'm too young for this. I'll gladly accept the beer though (I'm not that young ).
Anyway, here's some suggestions. I'm not a process-expert at all.
1. Post your script online man!
2. use cron? (if your script is not meant to go on forever)
3. use exec? (your terminal process will be replaced by the script)
Offline
i just used &, it seems to work...
Offline
Pages: 1