Search code examples
linuxbashinheritancetaskthread-priority

Can I prioritize Bash scripts in Linux, and do children of these scripts inherit the priority?


I have a script playing various movie clips on a computer using a video player. It's smooth. However, whenever a cron job is run where big files are to be downloaded, the video feed starts flickering. I believe this is due to the read/write needed to be done while downloading and playing at the same time.

My questions are:

  1. Can I prioritize a task in Linux?
  2. Can the prioritized task be a Bash script?

If so, will scripts and programs that run from that prioritized script inherit the priority?


Solution

  • You can set a process' priority with the nice command when launching the process, or with the renice command on existing processes.

    Any normal user processes can have a lower priority. Only root-owned processes can have a higher priority.

    To launch a lower priority process, use a command like:

    nice -10 mycommand.sh
    

    In this case the priority is 10 - which is a less favourable priority than normal; the process will have a lower priority on the system than a command not started with nice.

    Sub-processes inherit the same priority as their parent by default.