BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

Description:Create a memory limit for a process
Python
JoseluCross
import resource
def limit_memory(bytes):
    soft, hard = resource.getrlimit(resource.RLIMIT_AS)
    resource.setrlimit(resource.RLIMIT_AS, (bytes, hard))

Input example

2*(2**30)
16*(2**20)

Output example

Limit memory set in 2 GiB
Limit memory set in 16 MiB
×Oh snap! Something wrong