I want to limit the memory usage of a child process using rlimit. Currently our code is as follows:
old_rlimit := get_rlimit()
set_rlimit(child_process_rlimit)
cmd.Start()
set_rlimit(old_rlimit)
cmd.Wait()
However, sometimes Golang runtime will report out of memory error at cmd.Start()
. It seems that in cmd.Start()
current process will allocate some memory, and if current memory usage is higher than child_process_rlimit
, an error will be raised.
I want to know is there any way to limit the memory usage of child process without affecting current one?