1

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???

 PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
  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.

  • Have you tried adjusting process priorities? – dsstorefile1 Sep 17 '18 at 5:44
  • Using nice command? It still seems to be using high CPU even if i set lowest priority – OpenSourceEnthusiast Sep 17 '18 at 6:33
1
 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
          finish


   •   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 – OpenSourceEnthusiast Sep 17 '18 at 5:23
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.