1

我想在 Python 中创建一个进程(可能带有子进程和 Popen),它应该具有有限的 CPU 时间、有限的子进程和内存带宽。我找不到办法做到这一点。resource.setrlimit似乎不起作用。

我的代码是:

import os
import sys
import resource
import subprocess
import signal


def setlimits():
    os.seteuid(65534) # Has to run as root user in order to be able to setuid
    resource.setrlimit(resource.RLIMIT_CPU, (1, 1))
    resource.setrlimit(resource.RLIMIT_FSIZE, (500, 500))
    resource.setrlimit(resource.RLIMIT_NPROC, (80, 80))

p = subprocess.Popen( ["./exec.out"] , preexec_fn=setlimits )
4

0 回答 0