Trying to monitor a previous child process - Unix

This is a discussion on Trying to monitor a previous child process - Unix ; Hi, I currently have an application that monitors processes, however I can shutdown the app without bringing down the processes and this is fine. However when I restart the app I'm having serious problems trying to re-monitor the processes. I'm ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Trying to monitor a previous child process

  1. Trying to monitor a previous child process

    Hi,

    I currently have an application that monitors processes, however I can
    shutdown the app without bringing down the processes and this is
    fine. However when I restart the app I'm having serious problems
    trying to re-monitor the processes.

    I'm using the waitpid() system call to monitor the processes
    initially. However once the app is killed all the processes become
    orphaned and get init's pid as their ppid.

    Is there anyway of getting the application to re-monitor these
    processes? I can't think of any, as any of the wait* system calls only
    work with child processes, using them in this case will just result in
    them exiting straight away with -1.

    I don't think it's even possible to change the ppid of a process, due
    to the child sharing some of parents pages, file descriptors,
    resources, etc.

    So can anyone shed any light on this?

    Cheers,
    - Keith

  2. Re: Trying to monitor a previous child process

    Keith Halligan writes:
    > I currently have an application that monitors processes, however I can
    > shutdown the app without bringing down the processes and this is
    > fine. However when I restart the app I'm having serious problems
    > trying to re-monitor the processes.
    >
    > I'm using the waitpid() system call to monitor the processes
    > initially. However once the app is killed all the processes become
    > orphaned and get init's pid as their ppid.
    >
    > Is there anyway of getting the application to re-monitor these
    > processes?


    You could perhaps use ptrace or 'some other debugging facility'.

  3. Re: Trying to monitor a previous child process

    On Wed, 09 Apr 2008 07:14:29 -0700, Keith Halligan wrote:

    > Hi,
    >
    > I currently have an application that monitors processes, however I can
    > shutdown the app without bringing down the processes and this is fine.
    > However when I restart the app I'm having serious problems trying to
    > re-monitor the processes.
    >
    > I'm using the waitpid() system call to monitor the processes initially.
    > However once the app is killed all the processes become orphaned and get
    > init's pid as their ppid.
    >
    > Is there anyway of getting the application to re-monitor these
    > processes? I can't think of any, as any of the wait* system calls only
    > work with child processes, using them in this case will just result in
    > them exiting straight away with -1.
    >
    > I don't think it's even possible to change the ppid of a process, due to
    > the child sharing some of parents pages, file descriptors, resources,
    > etc.
    >
    > So can anyone shed any light on this?



    As I understand it, your monitoring app is initially the parent of the
    server processes. Have you tried to juggle with setpgid() yet ?

    Secondly, the existence of _processes_ does not guarantee their
    liveliness. When possible, you should try to perform _functional_ tests,
    such as connecting to them (if they have open ports), or checking for
    recently changed files.

    Since you appear to be the owner of the processes, kill(pid,0) could also
    be used to check for their existence. (but not their identity, of course)

    HTH,
    AvK

  4. Re: Trying to monitor a previous child process

    Keith Halligan wrote:
    > I currently have an application that monitors processes, however I can
    > shutdown the app without bringing down the processes and this is
    > fine. However when I restart the app I'm having serious problems
    > trying to re-monitor the processes.
    >
    > I'm using the waitpid() system call to monitor the processes
    > initially. However once the app is killed all the processes become
    > orphaned and get init's pid as their ppid.
    >
    > Is there anyway of getting the application to re-monitor these
    > processes? I can't think of any, as any of the wait* system calls only
    > work with child processes, using them in this case will just result in
    > them exiting straight away with -1.


    Solaris has a program called pwait. I don't have a Solaris system handy
    at the moment, but I know from previous experience that it can do what
    you are talking about.

    Looking at the source here:

    http://cvs.opensolaris.org/source/xr.../pwait/pwait.c

    .... it would appear it does some tricky stuff which involves opening
    a separate files /proc/N/psinfo for every pid N, then doing a poll()
    to get informed when they close.

    I don't know if they are relying on Solaris-specific poll() behavior,
    but it seems at least possible that this could be portable to other
    operating systems that have poll().

    It's also something that I would view as a last resort, BTW. :-)

    - Logan

  5. Re: Trying to monitor a previous child process

    Logan Shaw writes:
    >Keith Halligan wrote:
    >> I currently have an application that monitors processes, however I can
    >> shutdown the app without bringing down the processes and this is
    >> fine. However when I restart the app I'm having serious problems
    >> trying to re-monitor the processes.
    >>
    >> I'm using the waitpid() system call to monitor the processes
    >> initially. However once the app is killed all the processes become
    >> orphaned and get init's pid as their ppid.
    >>
    >> Is there anyway of getting the application to re-monitor these
    >> processes? I can't think of any, as any of the wait* system calls only
    >> work with child processes, using them in this case will just result in
    >> them exiting straight away with -1.

    >
    >Solaris has a program called pwait. I don't have a Solaris system handy
    >at the moment, but I know from previous experience that it can do what
    >you are talking about.
    >
    >Looking at the source here:
    >
    > http://cvs.opensolaris.org/source/xr.../pwait/pwait.c
    >
    >... it would appear it does some tricky stuff which involves opening
    >a separate files /proc/N/psinfo for every pid N, then doing a poll()
    >to get informed when they close.
    >
    >I don't know if they are relying on Solaris-specific poll() behavior,
    >but it seems at least possible that this could be portable to other
    >operating systems that have poll().


    It's not really poll() that matters, but rather the SVR4-based
    procfs in solaris, which is radically different from the procfs
    in linux.

    The filesystem needs to support poll operations for poll() to be
    able to use it, I'm doubtful that linux does, since they don't use
    procfs (/proc) as a debugger interface like SVR4/Solaris; linux
    instead uses enhanced ptrace(2).

    scott

+ Reply to Thread