2

I got a script that backs up minecraft worlds, when ran by command (nice -19 ./backup.sh) it doesn't lag what so ever, server load stays low. When I try to do nice -19 ./backup.sh in a cronjob, it doesn't "nice" it and it uses a high amount of server resources. Isn't there a renice command? Can't I some how input that in the code to make it renice itself everytime it runs? But how would I get the PID of the script?

Thank you!

  • Firstly this doesn't belong on stackoverflow. 2ndly: which user are you doing this as? Thirdly: you're misinterpreting nice. If it does use lots of CPUs it's most likely doing the right thing in cron. -19 is a "totally not nice" niceness. -20 is the highest priority, 19 is the lowest. Normal users can only do nicenesses from 0 to 19. Only root can do negative. – tink Apr 15 '13 at 21:14
  • 1
    @tink - `nice -10 ` isn't "minus 19", it's usually interpreted as `plus 19` althoug the correct form would be [`nice -n 10 `](http://man.he.net/?topic=nice&section=all) – mata Apr 15 '13 at 22:02
  • ta :) for the feedback, can't edit my comment any more :/ – tink Apr 15 '13 at 22:17

1 Answers1

0

Inside your script you should both renice it and ionice it, e.g. in bash:

#!/bin/bash

renice 19 -p $$
ionice -c 3 -p $$

...

The $$ in bash stands for the process ID of the current bash.

Urist McDev
  • 121
  • 2