Find the answer to your Linux question:
Results 1 to 3 of 3
I've got a script that I run as a cron job, and I'd like to drop its priority using "nice". Can I just call the entire script with "nice", or ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,414

    Using "nice" on a script


    I've got a script that I run as a cron job, and I'd like to drop its priority using "nice". Can I just call the entire script with "nice", or should I edit the script to call each of its internal functions with nice?

    In other words,
    Code:
    less /usr/local/sbin/sysupdate.sh
    
    #!/bin/bash
    nice /usr/bin/emerge --sync
    nice /usr/bin/emerge -uDN --world
    Then just call /usr/loca/sbin/sysupdate.sh normally, or remove all the "nice" statements in the script and call it like this,
    Code:
    nice /usr/local/sbin/sysupdate.sh
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Quote Originally Posted by smolloy
    Can I just call the entire script with "nice", or should I edit the script to call each of its internal functions with nice?
    You don't need the nice statements within the script (assuming you want the script and all its children processes to have the same nice value). The children will inherit niceness from the parent.

    Example:
    Code:
    [ceyan@troy ~]$ cat some-script.bash 
    #!/bin/bash
    ./some-child.bash &
    sleep 100
    exit 0
    
    [ceyan@troy ~]$ cat some-child.bash 
    #!/bin/bash
    sleep 100
    exit 0
    
    [ceyan@troy ~]$ nice -n 12 ./some-script.bash & 
    [1] 22949
    
    [ceyan@troy ~]$ ps -eo pid,comm,ni | head -1 && ps -eo pid,comm,ni | grep 'some-'
      PID COMMAND           NI
    22949 some-script.bas   12
    22950 some-child.bash   12
    As demonstrated here, both the parent and child have the same nice value of 12.

  3. #3
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,414
    Thanks anomie. Calling the entire script with "nice" will give all child functions the same nice value, just as I want.

    Thanks.
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •