FBB::Fork

libbobcat-dev_3.22.00-x.tar.gz

2005-2014


FBB::Fork(3bobcat)

FBB::Fork(3bobcat)

libbobcat-dev_3.22.00-x.tar.gz Template Design Pattern around fork(2)

2005-2014

NAME

FBB::Fork - Implements fork(2) using the Template Design Pattern

SYNOPSIS

#include <bobcat/fork>
Linking option: -lbobcat

DESCRIPTION

FBB::Fork objects may be used to implement the fork(2) call as part of the Template Algorithm Design Pattern. The class was designed as a virtual base class for classes implementing the essential parts of the forking process. The class is a virtual base class. Derived classes must implement the members childProcess() and parentProcess() as part of the `Template Method Design Pattern' (see Gamma et al., 1995).

Terminating child processes send SIGCHLD signals to their parents. The C library offers the following macros to analyze the status values received by the parent process using a wait(2) or waitpid(2) system call:

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

CONSTRUCTORS

Note that there is no copy constructor.

DESTRUCTOR

MEMBER FUNCTIONS

PROTECTED MEMBER FUNCTIONS

EXAMPLE

#include <iostream>
#include <unistd.h>

#include <bobcat/fork>

using namespace std;
using namespace FBB;

class Background: public Fork
{
    public:
        void childProcess();
        void parentProcess();
};

void Background::childProcess()
{
    for (int idx = 0; idx < 3; ++idx)
    {
        cout << "Hello world # " << idx << endl;
        sleep(1);
    }
    throw 0;    // caught in main()
}    

void Background::parentProcess()
{
    cout << "Waiting for the child process to end...\n";

    cout << "The child returns value " << waitForChild() << endl;
}    

int main()
try
{
    Background bg;

    bg.fork();
    cout << "This is from the parent\n";

    return 0;
}
catch(int x)
{
    cout << "The child terminates with: " << x << endl;
    return x;
}


FILES

bobcat/fork - defines the class interface

SEE ALSO

bobcat(7), ipipe(3bobcat), fork(2), opipe(3bobcat), pipe(3bobcat), redirector(3bobcat), wait(2), waitpid(2)

BUGS

None Reported.

DISTRIBUTION FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).