def _kill_process(self, pid, cgroups=None, sig=signal.SIGKILL):
        """
        Try to send signal to given process, either directly of with sudo.
        Because we cannot send signals to the sudo process itself,
        this method checks whether the target is the sudo process
        and redirects the signal to sudo's child in this case.
        """
        if self._user is not None:
            if not cgroups:
                cgroups = find_cgroups_of_process(pid)
            # In case we started a tool with sudo, we cannot kill the started
            # process itself, because sudo always runs as root.
            # So if we are asked to kill the started process itself (the first
            # process in the cgroup), we instead kill the child of sudo
            # (the second process in the cgroup).
            pids = cgroups.get_all_tasks(FREEZER)
            try:
                if pid == next(pids):
                    pid = next(pids)
            except StopIteration:
                # pids seems to not have enough values
                pass
            finally:
                pids.close()
        self._kill_process0(pid, sig)
Try to send signal to given process, either directly of with sudo.
        Because we cannot send signals to the sudo process itself,
        this method checks whether the target is the sudo process
        and redirects the signal to sudo's child in this case.