# -*- coding: utf-8 -*-
"""只操作本程序创建的临时对象；全部数据为合成样本。"""
import os, sys, json, sqlite3, tempfile, pathlib, subprocess, time, socket, stat
from pathlib import Path
def emit(**kw):
    print(json.dumps(kw, ensure_ascii=False, sort_keys=True))
soft=128; descriptors=list(range(120)); shell_limit=65535
remaining=soft-len(descriptors)
assert remaining==8 and shell_limit>soft
native=None
if os.name=='posix':
    code='import resource,os,json; resource.setrlimit(resource.RLIMIT_NOFILE,(64,64)); print(json.dumps({"soft":resource.getrlimit(resource.RLIMIT_NOFILE)[0],"fd":len(os.listdir("/proc/self/fd"))}))'
    native=json.loads(subprocess.check_output([sys.executable,'-c',code],universal_newlines=True)); assert native['soft']==64
emit(synthetic_service_soft=soft,synthetic_open_fds=len(descriptors),remaining=remaining,shell_limit=shell_limit,native_child=native,scope='资源限制只施加到新建子进程')
