def kill_win_last_proc(session,win="-1",sig="TERM"): import signal,os,platform ss=ScreenSaver(session,'/dev/null','/dev/null') ctty=ss.tty(win) if platform.system() == 'FreeBSD': pids=sc.get_tty_pids(ctty) else: pids=sc._get_tty_pids_pgrep(ctty) pid = pids[-1] sig=eval('signal.SIG'+sig) os.kill(int(pid),sig)
def get_win_last_proc(session, win="-1", ctty = None): import platform if not ctty: ss = ScreenSaver(session, '/dev/null', '/dev/null') ctty = ss.tty(win) if ctty is None or ctty == -1: stderr.write("Window does not exist (%s)\n" % win) return False if platform.system() == 'FreeBSD': pids = sc.get_tty_pids(ctty) else: pids = sc._get_tty_pids_pgrep(ctty) if len(pids) > 0: return pids[-1] else: ## No processes for this window. return None
def get_win_last_proc(session, win="-1", ctty=None): import platform if not ctty: ss = ScreenSaver(session, '/dev/null', '/dev/null') ctty = ss.tty(win) if ctty is None or ctty == -1: stderr.write("Window does not exist (%s)\n" % win) return False if platform.system() == 'FreeBSD': pids = sc.get_tty_pids(ctty) else: pids = sc._get_tty_pids_pgrep(ctty) if len(pids) > 0: return pids[-1] else: ## No processes for this window. return None
cwin = sc.get_current_window(session) if tdir.startswith('/') or tdir.startswith('~'): thedir = os.path.expanduser(tdir) else: if sourcenumber == "-1": f = os.popen(SCREEN + ' %s -Q @tty' % session_arg) else: f = os.popen(SCREEN + ' %s -p %s -Q @tty' % (session_arg, sourcenumber)) ctty = f.readline() f.close() if ctty.startswith('/dev'): if platform.system() == 'FreeBSD': pids = sc.get_tty_pids(ctty) else: pids = sc._get_tty_pids_pgrep(ctty) try: p_i = [i for (i, x) in enumerate(pids) if x == ppid][0] - 1 thepid = pids[p_i] except: p_i = len(pids) - 1 thepid = pids[p_i] info = None while not info and p_i >= 0: try: info = sc.get_pid_info(thepid) except: p_i -= 1 thepid = pids[p_i]
if tdir.startswith('/') or tdir.startswith('~'): thedir = os.path.expanduser(tdir) else: if sourcenumber == "-1": f = os.popen(SCREEN + ' %s -Q @tty' % session_arg) else: f = os.popen(SCREEN + ' %s -p %s -Q @tty' % (session_arg, sourcenumber)) ctty = f.readline() f.close() if ctty.startswith('/dev'): if platform.system() == 'FreeBSD': pids = sc.get_tty_pids(ctty) else: pids = sc._get_tty_pids_pgrep(ctty) try: p_i = [i for (i, x) in enumerate(pids) if x == ppid][0] - 1 thepid = pids[p_i] except: p_i = len(pids) - 1 thepid = pids[p_i] info = None while not info and p_i >= 0: try: info = sc.get_pid_info(thepid) except: p_i -= 1 thepid = pids[p_i]