def names_match_process_or_parents(proc, names):
    """Returns whether any of the given names are the name of the given
    psutil.Process or any of its parents."""

    if proc is None:
        return False
    elif any(name == proc.name().lower() for name in names):
        return True
    elif proc.parent() is not None and proc.pid == proc.parent().pid:
        return False
    else:
        return names_match_process_or_parents(proc.parent(), names)