def is_pid_cmdline_correct(pid, match):
    """Ensure that the cmdline for a pid seems sane

    Because pids are recycled, blindly killing by pid is something to
    avoid. This provides the ability to include a substring that is
    expected in the cmdline as a safety check.
    """
    try:
        with open('/proc/%d/cmdline' % pid) as f:
            cmdline = f.read()
            return match in cmdline
    except EnvironmentError:
        return False
