You are not logged in.

#1 2008-03-05 19:13:49

nDray
Member
From: Portugal
Registered: 2007-01-21
Posts: 143
Website

send script to background

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

#2 2008-03-05 19:42:12

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: send script to background

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

#3 2008-03-05 20:42:52

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: send script to background

"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

#4 2008-03-05 21:07:32

nDray
Member
From: Portugal
Registered: 2007-01-21
Posts: 143
Website

Re: send script to background

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

#5 2008-03-07 02:59:21

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: send script to background

Wow, T-Dawg is back! Beers all round!

Dusty

Offline

#6 2008-03-07 03:00:58

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: send script to background

who?
mwuhahahah....

Offline

#7 2008-03-07 19:05:24

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: send script to background

wot? I'm too young for this. I'll gladly accept the beer though (I'm not that young wink).

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

#8 2008-03-07 19:07:13

nDray
Member
From: Portugal
Registered: 2007-01-21
Posts: 143
Website

Re: send script to background

i just used &, it seems to work...

Offline

Board footer

Powered by FluxBB