Can proc A see proc B - SUN

This is a discussion on Can proc A see proc B - SUN ; I have a program that is run from a script. I have another program that has to start the script, monitor that the first program is running and send a signal to the first program. How can I find the ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Can proc A see proc B

  1. Can proc A see proc B

    I have a program that is run from a script.
    I have another program that has to start the script, monitor that the
    first program is running and send a signal to the first program. How
    can I find the PID of the first program? Thanks.

    Scott Klein
    Northrop Grumman Electronic Systems
    s.klein@ngc.com


  2. Re: Can proc A see proc B

    s.klein@ngc.com wrote:

    > I have a program that is run from a script.
    > I have another program that has to start the script, monitor that the
    > first program is running and send a signal to the first program. How
    > can I find the PID of the first program? Thanks.
    >
    > Scott Klein
    > Northrop Grumman Electronic Systems
    > s.klein@ngc.com
    >


    Run the program in the background and capture $!:

    foo &
    pid=$!
    echo "$pid"

    Regards,

    Ed.

  3. Re: Can proc A see proc B

    $$ also holds the PID for the current program (just to be complete).

    -Jeff


  4. Re: Can proc A see proc B

    In article ,
    Ed Morton wrote:

    > s.klein@ngc.com wrote:
    >
    > > I have a program that is run from a script.
    > > I have another program that has to start the script, monitor that the
    > > first program is running and send a signal to the first program. How
    > > can I find the PID of the first program? Thanks.
    > >
    > > Scott Klein
    > > Northrop Grumman Electronic Systems
    > > s.klein@ngc.com
    > >

    >
    > Run the program in the background and capture $!:


    That will get the PID of the script, not the program that the script
    starts.

    So he needs to modify the script so it runs the program in the
    background, then writes $! somewhere that the outer program can read it.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  5. Re: Can proc A see proc B

    In ,
    Barry Margolin mentions:
    >That will get the PID of the script, not the program that the script
    >starts.
    >
    >So he needs to modify the script so it runs the program in the
    >background, then writes $! somewhere that the outer program can read it.


    A favorite of mine (won't work if the program being run goes into
    the background)

    #
    # Might want to do stuff here to keep from running twice.
    #
    #
    echo $$ >pidfile
    exec program

    That way you don't have the overhead of a script hanging around.

    Jamie
    --
    http://www.geniegate.com Custom web programming
    guhzo_42@lnubb.pbz (rot13) User Management Solutions

  6. Re: Can proc A see proc B

    Thnaks for the advice, but my understanding and need is at a lower
    level.

    I have a script:
    set env variables
    run prog_b

    I have a C program with:
    if prog_b is not running
    {
    start script in background
    }
    else if signal command
    {
    send signal to prog_b
    }

    What do I need to do so that the C program can know if the program is
    running and how to send a signal to it? Thanks again.

    Scott Klein
    Northrop Grumman Electronic Systems
    s.klein@ngc.com


  7. Re: Can proc A see proc B

    In article <1158518845.466455.236740@i3g2000cwc.googlegroups.c om>,
    s.klein@ngc.com wrote:

    > Thnaks for the advice, but my understanding and need is at a lower
    > level.
    >
    > I have a script:
    > set env variables
    > run prog_b
    >
    > I have a C program with:
    > if prog_b is not running
    > {
    > start script in background
    > }
    > else if signal command
    > {
    > send signal to prog_b
    > }
    >
    > What do I need to do so that the C program can know if the program is
    > running and how to send a signal to it? Thanks again.


    As someone else pointed out, if you change the script to use the "exec"
    command to run prog_b, then prog_b's PID will be the same as the
    original script's. So when the C program starts the script in the
    background, it can use the PID returned by the fork() function to send
    the signal.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  8. Re: Can proc A see proc B

    Thanks.

    I had some problems getting it to work, until I realized that I needed
    to start the script will execlp and not system. Then, it worked. Thank
    you for you help.
    Scott


+ Reply to Thread