35 lines
864 B
Python
35 lines
864 B
Python
# -*- coding: utf-8 -*-
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
def getRuningProgramPids(progname):
|
|
pids = []
|
|
lines = os.popen('ps -ef | grep %s' % progname).readlines()
|
|
for l in lines:
|
|
line = ''
|
|
oldc = ''
|
|
for c in l.strip():
|
|
if c in [' ', '\t'] and c == oldc:
|
|
continue
|
|
oldc = c
|
|
line += c
|
|
line = line.split(' ')
|
|
|
|
if line[7] == './%s' % progname:
|
|
pids.append(line[1])
|
|
return pids
|
|
|
|
def monitor_ms(gameid):
|
|
gameid = gameid.strip();
|
|
if gameid== '':
|
|
return
|
|
while True:
|
|
pids = getRuningProgramPids(f'masterserver{gameid}')
|
|
if len(pids) <= 0:
|
|
print('zzzz')
|
|
os.popen(f'nohup ./masterserver{gameid} -n1 -i1 -f1,2,4 >> masterserver{gameid}.out 2>&1 &')
|
|
time.sleep(2)
|
|
|
|
monitor_ms(sys.argv[1])
|