本文整理汇总了Python中GNUScreen.get_tty_pids方法的典型用法代码示例。如果您正苦于以下问题:Python GNUScreen.get_tty_pids方法的具体用法?Python GNUScreen.get_tty_pids怎么用?Python GNUScreen.get_tty_pids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GNUScreen
的用法示例。
在下文中一共展示了GNUScreen.get_tty_pids方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
def dump(ss,minwin,maxwin):
for win,type,title in sc.gen_all_windows(minwin,maxwin,ss.pid):
if type==0:
type_string="basic"
elif type==1:
type_string="group"
elif type==-1:
type_string="zombie"
else:
type_string="unknown"
print("%s %s"%(win,type_string))
print("%s %s"%(win,title))
filter=ss.get_exec(win)
if filter!=-1:
print("%s %s"%(win,filter))
tty=ss.tty(win)
print("%s %s"%(win,tty))
if type==0:
try:
pids=sc.get_tty_pids(tty)
except:
print ("%s No access"%win)
pass
for pid in pids:
try:
print ("%s %s %s"%(win,pid,sc.get_pid_info(pid)))
except:
print ("%s No permission"%(win))
print("\n")
示例2: kill_win_last_proc
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
def kill_win_last_proc(session,win="-1",sig="TERM"):
import signal,os
ss=ScreenSaver(session,'/dev/null','/dev/null')
ctty=ss.tty(win)
pids=sc.get_tty_pids(ctty)
pid = pids[len(pids)-1]
sig=eval('signal.SIG'+sig)
os.kill(int(pid),sig)
示例3: kill_win_last_proc
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
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)
示例4: dump
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
def dump(ss,showpid=True,reverse=True,sort=False,groupids=[]):
from sys import stdout
bShow=True
windows=[]
if groupids:
windows=subwindows(ss.pid,groupids)[1]
for cwin,cgroupid,cgroup,ctty,ctype,ctypestr,ctitle,cfilter,cscroll,ctime in sc.gen_all_windows_full(ss.pid,reverse,sort):
if groupids:
if cwin in windows:
bShow=True
else:
bShow=False
if bShow:
print("----------------------------------------")
lines=[]
lines.append("%s TYPE %s\n"%(cwin,ctypestr))
if cgroupid=='-1':
groupstr='-1'
else:
groupstr=cgroupid+' '+cgroup
lines.append("%s GRP %s\n"%(cwin,groupstr))
lines.append("%s TITL %s\n"%(cwin,ctitle))
if cfilter!='-1':
lines.append("%s EXEC %s\n"%(cwin,cfilter))
if ctype==0:
lines.append("%s TTY %s\n"%(cwin,ctty))
if showpid:
try:
pids=sc.get_tty_pids(ctty)
except:
lines.append ("%s No access\n"%cwin)
pass
for pid in pids:
try:
cwd,exe,cmd=sc.get_pid_info(pid)
lines.append ("%s PID %s CWD %s\n"%(cwin,pid,cwd))
lines.append ("%s PID %s EXE %s\n"%(cwin,pid,exe))
cmd=cmd.split('\0')[:-1]
lines.append ("%s PID %s CMD %s\n"%(cwin,pid,cmd))
try:
if cmd[0].endswith('screen-session-primer') and cmd[1]=='-p':
lines[0]=lines[0][:-1]+" / primer\n"
elif cmd[0] in ('vi','vim','viless','vimdiff'):
lines[0]=lines[0][:-1]+" / VIM\n"
except:
pass
except:
lines.append ("%s PID > %s < No permission\n"%(cwin,pid))
map(stdout.write,lines)
示例5: get_win_last_proc
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
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
示例6: out
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
bPrint = False
session = "%s" % sys.argv[1]
out("session = " + session, bPrint)
session_arg = "-S %s" % session
cwin = sc.get_current_window(session)
windows_old = sc.parse_windows(sc.get_windows(session))[0]
out(str(windows_old), bPrint)
f = os.popen("screen %s -Q @tty" % session_arg)
ctty = f.readline()
f.close()
out(ctty, bPrint)
pids = sc.get_tty_pids(ctty)
# pids=sc.sort_by_ppid(pids)
thepid = pids[len(pids) - 1]
thedir = sc.get_pid_info(thepid)[0]
out(thedir, bPrint)
os.chdir(thedir)
# command='screen %s -X screen' % (session_arg)
command = "screen"
if len(sys.argv) > 2:
command += ' -t "%s"' % (" ".join(["%s" % v for v in sys.argv[2:]]))
else:
command += ' -t "%s"' % (thedir)
示例7: __save_screen
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
def __save_screen(self):
errors = []
homewindow = self.homewindow
group_wins = {}
group_groups = {}
excluded_wins = []
excluded_groups = []
scroll_wins = []
scroll_groups = []
cwin = -1
ctty = None
cppids = {}
rollback = (None, None, None)
ctime = self.time()
findir = sc.datadir
os.symlink(os.path.join(findir), os.path.join(self.basedir, self.savedir))
# sc_cwd=self.command_at(True,'hardcopydir') # it only works interactively
# should be modified to properly restore hardcopydir(:dumpscreen settings)
self.command_at(
False, "eval 'hardcopydir \"%s\"' 'at \"\#\" hardcopy -h' 'hardcopydir \"%s\"'" % (findir, self.homedir)
)
mru_w = [homewindow + "\n"]
for (
cwin,
cgroupid,
cgroup,
ctty,
ctype,
ctypestr,
ctitle,
cfilter,
cscroll,
badctime,
cmdargs,
) in sc.gen_all_windows_full(self.pid, sc.datadir, False, False):
mru_w.append("%s\n" % cwin)
cpids = None
cpids_data = None
if ctypestr[0] == "g":
pass
elif ctypestr[0] == "z":
cpids = []
else:
# get sorted pids associated with the window
try:
cpids = sc.get_tty_pids(ctty)
cpids_data = []
ncpids = []
for pid in cpids:
try:
pidinfo = sc.get_pid_info(pid)
(exehead, exetail) = os.path.split(pidinfo[1])
if exetail in self.blacklist:
blacklist = True
else:
blacklist = False
cpids_data.append(pidinfo + tuple([blacklist]))
ncpids.append(pid)
except Exception, x:
if cwin != homewindow:
errors.append("%s PID %s: Unable to access ( %s )" % (cwin, pid, str(x)))
cpids = ncpids
except Exception, x:
errors.append("%s Unable to access %s ( %s )" % (cwin, str(ctty), str(x)))
cpids = []
示例8: dump
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
def dump(ss, datadir, showpid=True, reverse=True, sort=False, groupids=[]):
from sys import stdout
bShow = True
windows = []
sum_process_total = 0
sum_win = 0
sum_zombie = 0
sum_basic = 0
sum_group = 0
sum_telnet = 0
sum_primer = 0
sum_vim = 0
if groupids:
(groups, windows) = subwindows(ss.pid, datadir, groupids)
try:
for (
cwin,
cgroupid,
cgroup,
ctty,
ctype,
ctypestr,
ctitle,
cfilter,
cscroll,
ctime,
cmdargs,
) in sc.gen_all_windows_full(ss.pid, datadir, reverse, sort):
if groupids:
if cwin in windows:
bShow = True
else:
bShow = False
if bShow:
sum_win += 1
if ctype == -1:
sum_zombie += 1
elif ctype == 0:
sum_basic += 1
elif ctype == 1:
sum_group += 1
elif ctype == 2:
sum_telnet += 1
print "----------------------------------------"
lines = []
lines.append("%s TYPE %s\n" % (cwin, ctypestr))
if cgroupid == "-1":
groupstr = "-1"
else:
groupstr = cgroupid + " " + cgroup
lines.append("%s GRP %s\n" % (cwin, groupstr))
lines.append("%s TITL %s\n" % (cwin, ctitle))
cmdargs = cmdargs.split('\0')
pcmdargs = cmdargs[0]
if cmdargs[1] != '':
pcmdargs += " " + (" ").join(["\"%s\"" % v for v in
cmdargs[1:-1]])
lines.append("%s CARG %s\n" % (cwin, pcmdargs))
if cfilter != "-1":
lines.append("%s EXEC %s\n" % (cwin, cfilter))
if ctype == 0:
lines.append("%s TTY %s\n" % (cwin, ctty))
if showpid:
try:
pids = sc.get_tty_pids(ctty)
for pid in pids:
sum_process_total += 1
try:
(cwd, exe, cmd) = sc.get_pid_info(pid)
lines.append("%s PID %s CWD %s\n" % (cwin,
pid, cwd))
lines.append("%s PID %s EXE %s\n" % (cwin,
pid, exe))
cmd = cmd.split('\0')
pcmd = cmd[0]
if cmd[1] != '':
pcmd += " "+" ".join(["\"%s\"" % v for v in cmd[1:-1]])
lines.append("%s PID %s CMD %s\n" % (cwin,
pid, pcmd))
if cmd[0].endswith('screen-session-primer') and cmd[1] == '-p':
sum_primer += 1
lines[0] = lines[0][:-1] + " / primer\n"
elif cmd[0] in ('vi', 'vim', 'viless', 'vimdiff'):
sum_vim += 1
lines[0] = lines[0][:-1] + " / VIM\n"
except OSError,x:
lines.append("%s PID %s Unable to access pid data ( %s )\n" %
(cwin, pid, str(x)))
except Exception,x:
lines.append("%s Unable to access PIDs associated with tty ( %s )\n" %
(cwin,str(x)))
try:
map(stdout.write, lines)
except:
break
print 'WINDOWS: %d\t[ %d basic | %d group | %d zombie | %d telnet ]' % \
#.........这里部分代码省略.........
示例9: __save_screen
# 需要导入模块: import GNUScreen [as 别名]
# 或者: from GNUScreen import get_tty_pids [as 别名]
def __save_screen(self):
errors=[]
homewindow=self.homewindow
group_wins={}
group_groups={}
excluded_wins=[]
excluded_groups=[]
scroll_wins=[]
scroll_groups=[]
cwin=-1
ctty=None
cppids={}
rollback=None,None,None
ctime=self.time()
findir=os.path.join(self.basedir,self.savedir)
#sc_cwd=self.command_at(True,'hardcopydir')
#print(sc_cwd)
self.command_at(False, 'at \# dumpscreen window %s'%os.path.join(self.basedir,self.savedir,"winlist"))
self.command_at(False, 'at \# dumpscreen window %s -F'%os.path.join(self.basedir,self.savedir))
self.command_at(False, 'hardcopydir %s'%os.path.join(self.basedir,self.savedir))
self.command_at(False, 'at \# hardcopy -h')
self.command_at(False, 'hardcopydir \"%s\"'%self.homedir) # should be modified to properly restore hardcopydir(:dumpscreen settings)
try:
f=open(os.path.join(findir,"winlist"),'r')
f.close()
except:
self.command_at(False, 'at \# dumpscreen window %s'%os.path.join(self.basedir,self.savedir,"winlist"))
fmru = open(os.path.join(findir,"mru"),"w")
for line in open(os.path.join(findir,"winlist"),'r'):
try:
id,cgroupid,ctty,ctitle = line.strip().split(' ',3)
except:
id,cgroupid,ctty= line.strip().split(' ')
ctitle=None
cwin=id
fmru.write("%s "%cwin)
if(ctty[0]=='z'): # zombie
continue
if(ctty[0]=="g"): # group
ctype="group"
cpids = None
cpids_data=None
if self.excluded:
if cwin in self.excluded or ctitle in self.excluded:
excluded_groups.append(cwin)
try:
group_groups[cgroupid]+=[cwin]
except:
group_groups[cgroupid]=[cwin]
if self.scroll:
if cwin in self.scroll or ctitle in self.scroll:
scroll_groups.append(cwin)
try:
group_groups[cgroupid]+=[cwin]
except:
group_groups[cgroupid]=[cwin]
else:
if self.excluded:
if cwin in self.excluded or ctitle in self.excluded:
excluded_wins.append(cwin)
else:
try:
group_wins[cgroupid]+=[cwin]
except:
group_wins[cgroupid]=[cwin]
if self.scroll:
if cwin in self.scroll or ctitle in self.scroll:
scroll_wins.append(cwin)
else:
try:
group_wins[cgroupid]+=[cwin]
except:
group_wins[cgroupid]=[cwin]
if(ctty[0]=="t"): # telnet
ctype="telnet"
cpids = None
cpids_data=None
else:
ctype="basic"
# get sorted pids in window
cpids=sc.get_tty_pids(ctty)
cpids_data=[]
ncpids=[]
for pid in cpids:
try:
pidinfo=sc.get_pid_info(pid)
(exehead,exetail)=os.path.split(pidinfo[1])
if exetail in self.blacklist:
blacklist=True
else:
blacklist=False
cpids_data.append(pidinfo+tuple([blacklist]))
ncpids.append(pid)
except:
errors.append('%s PID %s: Unable to access. No permission or no procfs.'%(cwin,pid))
cpids=ncpids
if(cpids):
for i,pid in enumerate(cpids):
#.........这里部分代码省略.........