Launching And Detaching

Discussion in 'Perl Misc' started by Hal Vaughan, Sep 7, 2005.

  1. Hal Vaughan

    Hal Vaughan Guest

    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)?

    Thanks!

    Hal
     
    Hal Vaughan, Sep 7, 2005
    #1
    1. Advertising

  2. Hal Vaughan 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)?


    Just putting '&' at the end does not detach a process from the shell.

    man nohup
    perldoc perlipc


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Sep 8, 2005
    #2
    1. Advertising

  3. Hal Vaughan

    Guest

    Hal Vaughan <> 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
     
    , Sep 8, 2005
    #3
  4. Hal Vaughan

    Hal Vaughan Guest

    wrote:

    > Hal Vaughan <> 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


    A good idea. I was just reading up on it and didn't even know about that
    function. Thanks!

    Hal
     
    Hal Vaughan, Sep 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward
    Replies:
    2
    Views:
    420
    Edward
    Jul 3, 2004
  2. Attila Feher
    Replies:
    2
    Views:
    435
    Ron Natalie
    Sep 23, 2003
  3. Replies:
    1
    Views:
    329
    Vinay Sajip
    Feb 14, 2006
  4. Sean
    Replies:
    6
    Views:
    562
    Alf P. Steinbach
    Aug 4, 2005
  5. David Mark
    Replies:
    1
    Views:
    715
    dhtml
    Dec 17, 2011
Loading...

Share This Page