SourceForge.net Logo

AEM - The Linux Asynchronous Event Mechanism





Back to main page





























AEM Process Termination

DESCRIPTION

This module provides asynchronous notification for exiting processes in case of normal and abnormal terminations. It must be noted that this uses the AEM notification mechanism. The monitored (or client) processes require NO preparation and can be already be running. Notification is direct and asynchronous. The handler registered by the server process receives the pid of the dying process as well as its terminating code status in parameter.

DEFINITIONS

#include <aem.h>
This file is located in the directory  {AEMSRC}/include/user in the AEM source package. It must be installed and included with your source code.

libaem
This is the AEM library. It is located in the directory  {AEMSRC}/lib in the AEM source package. It must be installed and linked with your source code.

INTERFACES


The following set of API is provided by libaem.

int aemPEXIT_init (void);

Initialize the aem-pexit functionality.

int aemPEXIT_notify_register (int, void *)

This call register a handler specified in the second parameter to be called when the process, pid specified in the first parameter terminates.

The handler prototype is:

   
    void handler (int event_id, int process_id, int exit_code)

The first parameter is the event Id, the second parameter is the process id (pid) of the terminating process and the last parameter is its exit code.

EXAMPLE

The following example illustrates a server that gets asynchronous notification for process death using AEM. This example is also available in the examples that come with the source package.

#include <aem.h>

void pexit (int ed, int pid, int exit_code)
{
    printf ("pexit: process [%d] terminated with code=%d\n", pid, exit_code);
}

/*
 * Install a handler for the process given in parameter.
 *
 * call: pexit1 <pid>
 */
main (int argc, char **argv)
{
    int pid;
   
    if (argc != 2) {
        printf ("Usage: pexit1 <pid>\n");
        return;
    }

    aemPEXIT_init ();
   
    pid = atoi (argv[1]);
    if (pid > 0) {
        int id = aemPEXIT_notify_register (pid, pexit);
        if (id < 0) {
            perror ("");
            exit (1);
        }
       
        if (aemCORE_event_start (id) < 0) {
            perror ("");
            exit (1);
        }
       
        aemCORE_pause ();
    }
}