AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  How do I wait for a process to exit?

    Posted Fri January 15, 2010 04:04 PM

    Originally posted by: le_jawa


    Hello everyone!

    I've got a process management question that's kicking me around, and wanted to see if anyone else had a good solution for this...

    I have a script that runs a program in the foreground (uv, for any Universe admins here). That program in turn runs another job, attaches the child job to PID 1, and exits (a Universe Phantom). I need for that script to continue running until the background job (the Phantom) exits. I can easily grep the PID and run a while loop with a sleep to check for the process every few seconds or so. However, I'm wondering if there is a more elegant solution that would allow me to wait for the EXIT signal from that child process, and exit the script once I catch it. This should be less resource intensive than scripting a while loop.

    I looked at trap, but as far as I can tell, it will only monitor child processes of the current shell, which this job is not.

    I also considered wait, but it looks like that only works with background jobs managed by the shell's process management, which isn't the case either.

    So, does anyone know of a way to get the signal from that job and keep the script running until it can see that the process has exited?

    Thank you!
    Jason
    #AIX-Forum


  • 2.  Re: How do I wait for a process to exit?

    Posted Fri January 15, 2010 07:01 PM

    Originally posted by: shargus


    Is it necessary to attach the process to PID 1, rather than simply backgrounding it?

    If so, what about writing a wrapper script around the child process, and that wrapper gets attached to PID 1 instead? The wrapper could then send out a signal or something when it exits.

    You might also look at using SRC to manage the child process. I had to do something similar, and using SRC turned out to be the most elegant way of doing it.
    #AIX-Forum


  • 3.  Re: How do I wait for a process to exit?

    Posted Mon January 18, 2010 08:29 PM

    Originally posted by: SystemAdmin


    Maybe I am missing something. Why can't you run the child process in the background, and follow this by the "wait" command.
    #AIX-Forum


  • 4.  Re: How do I wait for a process to exit?

    Posted Tue January 19, 2010 06:32 AM

    Originally posted by: Montecarlo


    From memory (a long time ago) universe phantoms log their activity (to a log file) as specified by the universe configuration. There may also be a uv command line command that reports on the status of phantoms.
    Otherwise there is nothing elegant you can do from the shell. perl or c would allow management via ipc.
    Regards, Simon
    #AIX-Forum


  • 5.  Re: How do I wait for a process to exit?

    Posted Fri January 22, 2010 10:36 AM

    Originally posted by: le_jawa


    Shargus:

    Thanks for the suggestion to use SRC. I'm looking into that to see if I can get that to work. That sounds like the best overall solution.

    .Spook:
    Cool idea, but one I had already tried. Running it in the background caused other problems unfortunately, so can't be used.

    Montecarlo:
    We've looked at that, but we're trying to avoid a rewrite of the C program that's running this whole thing, which is where we would change the IPC code. Scripting's doing it for us,so we're trying to stick to that. Also, thanks for sharing your experience with Universe. I'm new to that little monster and am glad to see folks here who know it.

    All:
    Thanks everyone for the contributions. I really appreciate you chipping in and helping.

    Jason
    #AIX-Forum


  • 6.  Re: How do I wait for a process to exit?

    Posted Fri January 22, 2010 03:48 PM

    Originally posted by: shargus


    Some time ago I needed to run a second copy of SSHD that ran on a special port using it's own config file. I did it by creating a SRC resource for a wrapper script around sshd. It uses SRC to automatically restart, but if it's not configured correctly it turns the auto-restart off.

    You do have to use the "-D" option for sshd so it does NOT become a daemon.

    Register it with SRC using the following command:
    mkssys -s new_sshd -p /usr/local/bin/new_sshd -u 0 -R -d -Q -S -n 15 -f 9 -E 30 -G new_sshd

    Here's the script:

    #! /usr/bin/sh
    export PATH=/usr/bin:/usr/sbin

    PID=$$

    logger "$PID: new_sshd: Starting up new_sshd..."

    1. If new_sshd_config has not been set up, exit now.

    if ! -e /etc/new_sshd_config ;
    then
    logger "$PID: new_sshd: /etc/new_sshd_config does not exist. Exiting now."
    chssys -s new_sshd -O
    sleep 2
    stopsrc -s new_sshd
    exit 1
    fi

    1. if new_sshd_config has not been configured yet, exit now.

    if ;
    then
    logger "$PID: new_sshd: ListenAddress has not yet been configured. Exiting now."
    chssys -s new_sshd -O
    sleep 2
    stopsrc -s new_sshd
    exit 1
    fi

    1. if new_sshd has been configured, set it up to automatically restart if not already done.

    flag=`lssrc -S -s new_sshd | awk -F: ' $10 != "action" { print $10; } ' - `
    if ;
    then
    logger "$PID: new_sshd: Configuring new_sshd to start automatically at boot time."
    chssys -s new_sshd -R
    fi

    1. Start up the sshd daemon.
    2. Use the -D option so we don't exit. If we DO exit, SRC will restart us.

    logger "$PID: new_sshd: Starting new ssh server now."
    exec /usr/local/sbin/sshd -f /etc/new_sshd_config -D
    #AIX-Forum