October 6, 2015

Major Tom, This is Job Control - page 3

Acting Nice with the Linux System

  • July 27, 2000
  • By Jay Fink

We all know Linux is about small, clean utilities and tools that work well together. The aforementioned tools, commands and utilities are no different. As an example, lets say I have two jobs that run overnight. The first job is a tar job that makes a raw backup of my home filesystem. The second is a cleaner script for the system. Additionally, for the sake of argument, we will say during the night the system is doing downloads. Now we obviously want the backup to have a pretty high priority. So our crontab might look like this:

  0 2 * * * /usr/bin/nice -n 0 cd /home; tar -cf /dev/hdb myhome 2>&1
  0 0 * * * /bin/rm -rf /var/tmp/* 2>&1

So we ensure that the tar job has a priority of 0. (The default priorities are: c for at and E for batch.)

Here are some further examples of these commands in action.

To start a job off with a nice priority of 3 under Linux:

  nice 3 job_name

To lower a job's nice number and hence raising its priority to 3 with a PID of 1253:

  renice -n 3 -p 1253

simple background job submission
To enter commands into the background simply use the ampersand symbol:

  mv -f dirname_one new_dirname_one &
  mv -f dirname_two new_dirname_two &

To check the number of jobs and their status use:



To submit a script named exec_file.sh to the queues at 1400:

batch 1400 -f exec_file.sh

to submit a script to at named exec_file.sh at 1504:

  at -f exec_file.sh 1504

The cron fields are as follows from left to right (the top of the list being the leftmost field):

  - minutes_after_the_hour 
  - hours 
  - days_of_the_month 
  - months_of_the_year 
  - weekdays

To submit the file /home/myscripts/exec_file.sh to run at 3 a.m. every Monday:

  00 3 * * 1 /home/myscripts/exec_file.sh 2>&1
Sitemap | Contact Us