libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Public Attributes | List of all members
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 >

Public Member Functions

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

Public Attributes

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

Additional Inherited Members

- Static Public Member Functions inherited from ASSA::Singleton< ForkList >
static ForkListget_instance ()
 Return an instance of templated class T. More...
 
- Protected Member Functions inherited from ASSA::Singleton< ForkList >
 Singleton ()
 Protected Constructor. More...
 
virtual ~Singleton ()
 Virtual Destructor. More...
 

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.

235 { trace_with_mask("ForkList::ForkList",FORK); }
Class Fork messages.
Definition: LogMask.h:47
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition: Logger.h:437
ForkList::~ForkList ( )

Destructor. Wipe out childer based on their state.

Definition at line 188 of file Fork.cpp.

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

189 {
190  trace_with_mask("ForkList::~ForkList",FORK);
191 
192  list<fnode_t* >::iterator i;
193  pid_t pid;
194 
195  // Go through the list and send SIGTERM to those children
196  // whose flags were set at fork time.
197 
198  for (i = m_list.begin(); i != m_list.end(); i++) {
199  if ((*i)->needKill()) {
200  ::kill((*i)->getPID(), SIGTERM);
201  }
202  }
203  // Wait for all children to exit.
204 
205  while ( ! m_list.empty() ) { // wait for child to exit
206  pid = ::wait(NULL);
207  if ( pid < 0 ) { // error on wait
208  EL((ASSAERR,"Error on wait()\n"));
209  exit (EXIT_FAILURE);
210  }
211  // Search for child through the list by its pid.
212  // If found, remove it from list and release memory.
213 
214  list<fnode_t* >::iterator j;
215 
216  for (j = m_list.begin(); j != m_list.end(); j++) {
217  if ((*j)->getPID() == pid) {
218  fnode_t* ep = *j;
219  m_list.erase(j);
220  delete ep;
221  break;
222  }
223  }
224  }
225 }
ASSA and system errors.
Definition: LogMask.h:34
Class Fork messages.
Definition: LogMask.h:47
list< fnode_t * > m_list
List of children's data structures.
Definition: Fork.h:241
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition: Logger.h:437
#define EL(X)
A macro for writing error message to the Logger.
Definition: Logger.h:285
forknode_t class.
Definition: Fork.h:195

Member Data Documentation

list< fnode_t* > ASSA::ForkList::m_list

List of children's data structures.

Definition at line 241 of file Fork.h.

Referenced by ASSA::Fork::Fork(), and ~ForkList().


The documentation for this class was generated from the following files: