libassa 3.5.0
Public Member Functions | Public Attributes

ASSA::ForkList Class Reference

ForkList is a singleton class that keeps a list of all forked children. More...

#include <Fork.h>

Inheritance diagram for ASSA::ForkList:
ASSA::Singleton< ForkList >

List of all members.

Public Member Functions

 ForkList ()
 Constructor.
 ~ForkList ()
 Destructor. Wipe out childer based on their state.

Public Attributes

list< fnode_t * > m_list
 List of children's data structures.

Detailed Description

ForkList is a singleton class that keeps a list of all forked children.

Its task is on process exit, for each child forked, either terminate it with SIGTERM or wait for its exit. In any case, child's exit status is collected thus avoiding zombie processes.

Definition at line 231 of file Fork.h.


Constructor & Destructor Documentation

ASSA::ForkList::ForkList ( ) [inline]

Constructor.

Definition at line 235 of file Fork.h.

References ASSA::FORK, and trace_with_mask.

{ trace_with_mask("ForkList::ForkList",FORK); }
ForkList::~ForkList ( )

Destructor. Wipe out childer based on their state.

Definition at line 189 of file Fork.cpp.

References ASSA::ASSAERR, EL, ASSA::FORK, m_list, and trace_with_mask.

{
    trace_with_mask("ForkList::~ForkList",FORK);

    list<fnode_t* >::iterator i;
    pid_t pid;

    // Go through the list and send SIGTERM to those children
    // whose flags were set at fork time.

    for (i = m_list.begin(); i != m_list.end(); i++) {
        if ((*i)->needKill()) {
            ::kill((*i)->getPID(), SIGTERM);
        }
    }
    // Wait for all children to exit.

    while ( ! m_list.empty() ) { // wait for child to exit
        pid = ::wait(NULL);
        if ( pid < 0 ) { // error on wait
            EL((ASSAERR,"Error on wait()\n"));
            exit (EXIT_FAILURE);
        }
        // Search for child through the list by its pid.
        // If found, remove it from list and release memory.
        
        list<fnode_t* >::iterator j;
        
        for (j = m_list.begin(); j != m_list.end(); j++) {
            if ((*j)->getPID() == pid) {
                fnode_t* ep = *j;
                m_list.erase(j);
                delete ep;
                break;
            }
        }
    }
}

Member Data Documentation

List of children's data structures.

Definition at line 241 of file Fork.h.

Referenced by ~ForkList().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines