Using cpulimit to self-limit a script?

Discussion in 'Programming/Scripts' started by BorderAmigos, Jul 10, 2010.

  1. BorderAmigos

    BorderAmigos New Member

    I have a backup script that runs daily and I'd like to limit it's resource usage. The cpulimit program appears to do what I want. I'd like it to only run with this backup script though. I tried putting the command inside the script...

    #!/bin/sh
    cpulimit -P /path/this-script.sh -l 20
    ... rest of script

    But it just kills the script this way. The script is run on a cron job. Anyone have suggestions on how to make this work?

    One way may be to run cpulimit as a daemon but I'd prefer to run it only along with this script and not all the time.
     
  2. BorderAmigos

    BorderAmigos New Member

    Seems to be working by limiting the shell instead of the script.

    #!/bin/sh
    cpulimit -P /bin/sh -l 20
    ... rest of script

    EDIT: Guess not, still hangs up.
     
    Last edited: Jul 10, 2010
  3. falko

    falko Super Moderator Howtoforge Staff

    Take a look at nice:
    Code:
    man nice
     
  4. BorderAmigos

    BorderAmigos New Member

    Not real clear to me. So if I run with a lower number or higher number it would lower it's priority? Assuming it is running with 0 now

    nice -n 10 script.sh

    would increase or decrease its processor usage? Thanks.
     
  5. BorderAmigos

    BorderAmigos New Member

    I tried nice set to 15 and it's not slowing down the script. When I check the process list the NI value is 15 while all others are 0. But the CPU usage is still higher than I want.
     

Share This Page