The shell provides a lot of useful capabilities, and it is not very difficult to learn, or it is better to say "not more than C/C++ language". In these two language the user has to learn the language and also the compiler, and if he want to develop large projects it has to learn, also, an IDE.
Really the shell doesn't have the power of compiled languages, but it has a lot of flexibility, sometimes it is difficult to find some examples, but if you google a little you can find what you are looking for.
In C/C++ this task is very simple, take a look to the related posts. With the shell……
it is simpler!!
The first thing to say is that backgrounding the script won't demonize it.
Yes you really have to do some task to demonize your script:
- Disconnect stdin
- Disconnect stdout
- Disconnect stderr
- Ignore the hangup signal
the first three tasks will be implemented with the redirection
the last one will be implemented using the nohup tool.
from the Mac Man page
nohup -- invoke a utility immune to hangups
The nohup utility invokes utility with its arguments and at this time sets the signal SIGHUP to be ignored. If the standard output is a terminal, the standard output is appended to the file nohup.out in the current directory. If standard error is a terminal, it is directed to the same place as the standard output. Some shells may provide a builtin nohup command which is similar or identical to this utility. Consult the builtin(1) manual page.
The above command will do the work, so let's start.
you can type the following command:
# nohup ./thescript.sh 0<&- &>/dev/null &
# nohup ./thescript.sh 0<&- &> thescript.log &
# (./thescript.sh &) &