This question already has an answer here:
I have some binary I want to run in terminal, but if I run it, it quickly starts to use 100% of both CPUs, 100% of memory and the whole Linux freeze in a few seconds. Also I don't have source (in order to calm it down right from the inside). I googled a lot and found and tried two possible solutions:
nice- does literally nothing, the binary still uses 100% of both CPUs and 100% of memory quickly after I run it
ulimit -vmakes binary and even some other commands (like git) crash and throw some error
Is there any easy solution to limit CPU usage or memory by this binary and let it use e.g.
only one CPU or 50% of both CPUs or only some small amount memory? I imagine something like this:
user@linux:~$ magical_command --limitmemory 1M --command mybinary
user@linux:~$ magical_command --cpu both --limitcpu 50% --command mybinary
user@linux:~$ magical_command --cpu one --limitcpu 100% --command mybinary
Update: From the comments below it looks like it is caused by memory rather than CPU overload, therefore I edited the question, but I still recommend @dbkeys' answer for those looking for CPU limiting magical command.
Update 2: As requested in the comments below: if I restart my notebook and only run terminal and that binary from terminal, nothing else, my notebook is significantly slowed down, mouse and keyboard works with delays or jerkily. But the binary is working for hours (most of time downloading and compiling dependencies), therefore I open Chrome and do some other stuff. If I open Chrome and let the binary run in the background, the whole linux freezes at all and nothing, even not mouse responds. I have to push a switch-off buton for 5 seconds to hard shutdown. But I can't just run it and go away, I want to work on some other stuff, therefore I want to limit somehow maybe both, that binary and Chrome.