bash - Limit terminal command memory usage (previously CPU usage) - Ask Ubuntu


this question has answer here:

i have binary want run in terminal, if run it, starts use 100% of both cpus, 100% of memory , whole linux freeze in few seconds. don't have source (in order calm down right inside). googled lot , found , tried 2 possible solutions:

  1. nice - literally nothing, binary still uses 100% of both cpus , 100% of memory after run it
  2. ulimit -v makes binary , other commands (like git) crash , throw error

is there easy solution limit cpu usage or memory binary , let use e.g. only 1 cpu or 50% of both cpus or small amount memory? imagine this:

user@linux:~$ magical_command --limitmemory 1m --command mybinary 

or:

user@linux:~$ magical_command --cpu both --limitcpu 50% --command mybinary 

or:

user@linux:~$ magical_command --cpu 1 --limitcpu 100% --command mybinary 

update: comments below looks caused memory rather cpu overload, therefore edited question, still recommend @dbkeys' answer looking cpu limiting magical command.

update 2: requested in comments below: if restart notebook , run terminal , binary terminal, nothing else, notebook slowed down, mouse , keyboard works delays or jerkily. binary working hours (most of time downloading , compiling dependencies), therefore open chrome , other stuff. if open chrome , let binary run in background, whole linux freezes @ , nothing, not mouse responds. have push switch-off buton 5 seconds hard shutdown. can't run , go away, want work on other stuff, therefore want limit somehow maybe both, binary , chrome.

taskset, might 'magical_command' looking for. according man page:

"...taskset used set or retrieve cpu affinity of running process given pid, or launch new command given cpu affinity. cpu affinity scheduler property "bonds" process given set of cpus on system. linux scheduler honor given cpu affinity , process not run on other cpus. "

this limit mybinary run on first 2 cores:

taskset --cpu-list 0,1 mybinary 

unfortunately, don't see parameter in taskset limit % of cpu's time want allot run mybinary.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User