I have the following code in a Jupyter notebook:
import resource
resource.setrlimit(resource.RLIMIT_NPROC, (1024, 1024))
while True:
try:
pid = os.fork()
if pid != 0:
count += 1
else:
break
except Exception as e:
print(e)
print("COUNT: ", count)
From what I understand, this should keep forking until it hits 1024 and then an exception is caught and the number of created processes should be 1024.
When I ran this, the first time I got 896, but every time after, even the first fork wouldn't run.
I'm guessing the 896 is because of some Jupyter overhead, but why would the number of processes persist after an execution when I specifically reconnect so that popen is called anew?
What contributes to the nproc limit? Is it all child processes and forks? If so, is there any way I can get a list of these somehow?
I've tried reading children from /proc/self/task
, but the number of those is constant.
Also, is setting RLIMIT_NPROC
equivalent to running ulimit -u
in the Jupyter popen command? Is this equivalent to setting RLIMIT_NPROC
in the preexec_fn
?