I am running un tar i.e tar xzvf abc.tar.gz on Beaglebone green. This seems to be using too much CPU. When a untar operation is in progress, i see via top command the CPU usage.. not sure why it seems to be creating 2 different processes, any idea why???

  626   625 root     R     1956   1%  64% tar xzvf abc.tar.gz
  625   612 root     S     1960   1%  12% tar xzvf abc.tar.gz

How can I limit the untar process to not use too much CPU? There is a time critical real time process which isn't getting CPU and it gets effected whenever untar is run. Hence the need to limit untar in some way to not use more than may be 40 - 50 % of CPU at any time.

  • Using nice command? It still seems to be using high CPU even if i set lowest priority Sep 17, 2018 at 6:33

2 Answers 2

 cpulimit -fl 50 -- tar xzvf abc.tar.gz

man cpulimit:

   cpulimit -- limits the CPU usage of a process

   -l, --limit=N
          percentage of CPU allowed from 1 up. Usually 1 - 100, but can be
          higher on multi-core CPUs. (mandatory)

   -f, --foreground
          run cpulimit in foreground while waiting for launched process to

   •   cpulimit always sends the SIGSTOP and SIGCONT signals to a process,
       both to verify that it can control it  and  to  limit  the  average
       amount  of  CPU it consumes.  This can result in misleading (annoy‐
       ing) job control messages that  indicate  that  the  job  has  been
       stopped  (when  actually  it was, but immediately restarted).  This
       can also cause issues with interactive shells that detect or other‐
       wise  depend on SIGSTOP/SIGCONT.   For example, you may place a job
       in the foreground, only to see it immediately stopped and restarted
       in the background.
  • I would like to have a hard limit on the CPU usage. this is something which i think cpulimit doesn't do.. it tends to increase the CPU usage of the process when the processor is idle? Can you confirm Sep 17, 2018 at 5:23

You'd only want to limit CPU usage if your CPU was getting too hot or any problem that may arise when your CPU is getting fully used or when you don't want a task to run as quickly.

Not using it fully is just wasting CPU cycles on the "idle task"

If the problem is that you'd rather have another process get those CPU cycles in priority, then the solution is to lower the priority of tar/gzip, or in other words increase its niceness.

For instance, by using:

nice 20 tar...

Where 20 is the highest niceness. That way, tar will get few CPU cycles if other processes demand some, but will still use 100% CPU when the system has nothing else to do.

Now if your other process does really use real time priorities, then you shouldn't have to do that as the scheduler should give precedence to real time processes over normal processes, so it may be that the CPU is not the resource that your process can't get hold to and neither changing priority nor reducing CPU usage of tar will help.

You may want to also use ionice on tar:

nice 20 ionice -c idle tar...

Quoting the ionice man page:

Idle A program running with idle I/O priority will only get disk time when no other program has asked for disk I/O for a defined grace period. The impact of an idle I/O process on normal system activity should be zero.

  • 1
    nice 20 err'ed on my end ("nice: ‘20’: No such file or directory"), I then did nice -n 20 ... which is a bit pushing against the ceiling as nice -n 20 nice gave 19. and like everything else it worked like a charm! Thanks for pointing out ionice which just appeared working as announced and I didn't know about it earlier.
    – hakre
    Jun 11, 2021 at 21:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .