#ifndef INCLUDED_BOBCAT_FORK_
#define INCLUDED_BOBCAT_FORK_

#include <sys/types.h>

#include <iosfwd>

namespace FBB
{    

class Fork
{
    pid_t d_pid;

    public:
        virtual ~Fork();
        void fork();

    protected:
        pid_t pid() const;                                  // .f

        virtual void childRedirections();   // do child redirections
        virtual void childProcess() = 0;    // must be implemented

        virtual void parentRedirections();  // do parent redirections
        virtual void parentProcess() = 0;   // must be implemented

        void prepareDaemon() const;         // prepares for a daemon
        void prepareDaemon(std::string const &out,
                           std::string const &err,
                           mode_t mode = 0600) const;

        int waitForChild();                 // returns the status

    private:
        static void reopen(std::string const &out, mode_t mode);

};

#include "pid.f"

} // FBB

#endif



