libassa  3.5.1
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

◆ ForkList()

ASSA::ForkList::ForkList ( )
inline

Constructor.

Definition at line 235 of file Fork.h.

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

References ASSA::FORK, and trace_with_mask.

◆ ~ForkList()

ForkList::~ForkList ( )

Destructor. Wipe out childer based on their state.

Definition at line 187 of file Fork.cpp.

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 }
#define EL(X)
A macro for writing error message to the Logger.
Definition: Logger.h:285
list< fnode_t * > m_list
List of children's data structures.
Definition: Fork.h:241
forknode_t class.
Definition: Fork.h:195
@ ASSAERR
ASSA and system errors
Definition: LogMask.h:34

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

Member Data Documentation

◆ m_list

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: