'Try to attach to new forked process; mimic "attach -waitfor"
Usage:
MYNAME [cmdname]
MYNAME [cmdname] -c (auto continue after attached)'

def waitfor(self, *arg):

    (name, opt) = normalize_argv(arg, 2)
    if (name == '-c'):
        opt = name
        name = None
    if (name is None):
        filename = peda.getfile()
        if (filename is None):
            warning_msg('please    specify    the    file    to    debug    or    process    name    to    attach')
            return
        else:
            name = os.path.basename(filename)
    msg(('Trying    to    attach    to    new    forked    process    (%s),    Ctrl-C    to    stop...' % name))
    cmd = ('ps    axo    pid,command    |    grep    %s    |    grep    -v    grep' % name)
    getpids = []
    out = execute_external_command(cmd)
    for line in out.splitlines():
        getpids += [line.split()[0].strip()]
    while True:
        found = 0
        out = execute_external_command(cmd)
        for line in out.splitlines():
            line = line.split()
            pid = line[0].strip()
            cmdname = line[1].strip()
            if (name not in cmdname):
                continue
            if (pid not in getpids):
                found = 1
                break
        if (found == 1):
            msg(('Attching    to    pid:    %s,    cmdname:    %s' % (pid, cmdname)))
            if peda.getpid():
                peda.execute('detach')
            out = peda.execute_redirect(('attach    %s' % pid))
            msg(out)
            out = peda.execute_redirect(('file    %s' % cmdname))
            msg(out)
            if (opt == '-c'):
                peda.execute('continue')
            return
        time.sleep(0.5)
    return
