'`parent_func` is a function that\'s called every time the child
process dies.
`child_func` is a function that should be run by the forked child
that will auto-restart with the RESTART_EXIT_STATUS.'

@classmethod
def start(cls, parent_func, child_func=None):

    signal.signal(signal.SIGTERM, cls._handle_sigterm)
    cls.need_stop = False
    while True:
        try:
            if hasattr(cls, 'child_pid'):
                delattr(cls, 'child_pid')
            pid = os.fork()
            if (pid > 0):
                cls.child_pid = pid
                while (not cls.need_stop):
                    (cpid, status) = os.waitpid(pid, os.WNOHANG)
                    if ((cpid, status) != (0, 0)):
                        break
                    time.sleep(1)
                if (parent_func is not None):
                    parent_func()
                if cls.need_stop:
                    break
            elif (child_func is not None):
                child_func()
            else:
                break
        except OSError as e:
            msg = ('Agent    fork    failed:    %d    (%s)' % (e.errno, e.strerror))
            logging.error(msg)
            sys.stderr.write((msg + '\n'))
            sys.exit(1)
    if (pid > 0):
        sys.exit(0)
