Leaves no more than `num` instances of a program alive.  Ordering is
        determined by most recent usage.

        CommandLine:
            python -m utool.util_ubuntu XCtrl.killold gvim 2

        >>> import utool as ut
        >>> from utool import util_ubuntu
        >>> XCtrl = util_ubuntu.XCtrl
        >>> pattern = 'gvim'
        >>> num = 2

def killold(pattern, num=4):
        """
        Leaves no more than `num` instances of a program alive.  Ordering is
        determined by most recent usage.

        CommandLine:
            python -m utool.util_ubuntu XCtrl.killold gvim 2

        >>> import utool as ut
        >>> from utool import util_ubuntu
        >>> XCtrl = util_ubuntu.XCtrl
        >>> pattern = 'gvim'
        >>> num = 2

        """
        import utool as ut
        cmdkw = dict(verbose=False, quiet=True, silence=True)
        num = int(num)
        winid_list = XCtrl.findall_window_ids(pattern)
        winid_list = XCtrl.sort_window_ids(winid_list, 'mru')[num:]
        output_lines = ut.cmd(
            """wmctrl -lxp | awk '{print $1 " " $3}'""",
            **cmdkw)[0].strip().split('\n')
        output_fields = [line.split(' ') for line in output_lines]
        output_fields = [(int(wid, 16), int(pid)) for wid, pid in output_fields]
        pid_list = [pid for wid, pid in output_fields if wid in winid_list]
        import psutil
        for pid in pid_list:
            proc = psutil.Process(pid=pid)
            proc.kill()