Re: Launching And Detaching



Hal Vaughan <hal@xxxxxxxxxxxxxxxxxxxx> wrote:
> I'm using one simple program to launch some daemons. When I launch a
> program, I use backticks. (This is all on Linux, in bash, btw.) I've
> added "2>&1 >/dev/null &" to the command line, so it's like this:
>
> `/path/to/program 2>&1 >/dev/null &`;
>
> I've noticed that if I include the '&' so the program detaches from the
> shell, if I kill the launching program, the child process survives. I've
> also tried this by forking first:
>
> if (!fork()) {
> `/path/to/program 2>&1 >/dev/null &`;
> exit;
> }
>
> I had the hope that if I forked and launched like this, once all the
> programs were launched, the launching program would exit. It doesn't. Is
> there a way I can launch a program, then have the first program exit, so
> it's no longer using that bash instance (without killing it)?

You should not been using backticks for this purpose - they
are designed to collect data from the external program
and will wait for that program.

Have a look at: perldoc -f exec

Axel
.