March 21, 2019

Major Tom, This is Job Control

Acting Nice with the Linux System

  • July 27, 2000
  • By Jay Fink

Job control and scheduling is quickly becoming less and less of an issue for most Linux users and administrators. Virtually all scheduling is done (justifiably so) via cron. However, I have come across many occasions of late where using job control and processing techniques is quite handy. This article will look at two aspects of job control: first, priority scheduling and altering priorities with nice and renice, respectively; second, batch processing and scheduling using batch, at, and cron, respectively.

Nice and Renice
Many UNIX users are very familiar with nice and renice, and as they pertain to job control they deserve mention within this context. The nice command is used to alter an initial job priority. On Linux systems this is fairly simple: the lower the nice command the higher the priority. The range on a Linux system is -20 (being the highest) to 19 (the lowest). Using nice is pretty simple. Let's say we want to make sure that a compile and install for fetchmail has a pretty high priority. We might do the following:

  nice -n 5 make

We have lowered the nice number and raised the job priority initially for this task.

The renice command is used to alter the nice value of a job after it has been started. It is important to note that only root may alter the nice value of jobs it does not own, and non-root users may only alter their nice values between 0 and 20 (the former is obviously so users may not tamper with other users while the latter protects the privileged processes of the system). An example of using renice on a single process might look like so:

  renice 5 -p 10023

where we lower the nice value to 5 of PID 10023. The renice command can also affect entire group of processes as well. For instance, let us say we wanted all of jdoe user's processes to have a nice value of 12. The syntax on Linux would be:

  renice 12 -u jdoe

Processing and Scheduling Commands
Many times a user will want to run a large job but not wish to lock up a terminal waiting for it to finish. The fastest way to do this is to simply put it in the background. This will only work well for programs that do not print to STDOUT. For example, if I wanted to move a bunch of directories separately and in the background, I could do this:

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

The & is used to put the job in the background so my terminal is free for me to keep working. The system will inform me when the jobs are done. It is important not to logout while background jobs are running. On most systems you will see a warning message stating that there are running jobs. If this is ignored, the jobs will be terminated. To see the current jobs running, just type jobs and a list is printed out to the terminal. This output varies from shell to shell.

There are instances when putting jobs in the background alone is not enough. You may wish to logout after the job is started. This is where batch processing or scheduling comes in handy.

It is important to note at this point that at and batch are related on Linux systems and similarly implemented.

Most Popular LinuxPlanet Stories