Main index

Introducing UNIX and Linux


Processes and devices

Overview
Processes
      Process status
      Foreground and background
      Process control
      Signals
Environment
      Environment variables
      Global and local variables
      Executable scripts
Program control
      Job control
      Command history list
      Running a job at a specific time
      Running programs periodically
      Big programs
      Timing a program
      Running programs in order
Quotes and escapes
Devices
Backquotes
Summary
Exercises

Big programs

Some programs take a lot of processing time before they complete. If you are running such a program, and the results are not needed urgently, you would probably like it to be executing on a processor when the system is not busy, and for it to be suspended when the usage of the machine becomes high, in order not to slow down more urgent processes. The facility called nice (so called because you are being considerate to other users) exists to prioritise a job. If mycommand is a big program, then

nice mycommand &

will run mycommand in the background with low priority.

If a process is already running and you wish to reduce its priority, the command renice can be used, but we omit discussion of this command here - examine the manual page using man for further information.

When you finish your session on the system, a signal SIGHUP ('hangup') is sent to all the processes you created during the session. Most processes, when they receive this signal, will terminate. If you have a job you wish to continue running in the background after you have logged off - and this will probably be true for any big jobs you run - you must make the job immune to the signal SIGHUP by means of command nohup. The syntax is nohup followed by a command, you will probably also wish the command to run in the background:

nohup testfile &

You would only want to run a command via nohup in the foreground if you were connected to the system using a communication link that might disconnect you without warning in the middle of a session. Standard output and the standard error stream from a job running with nohup are redirected to a file called nohup.out instead of to your terminal, if they are not already redirected, and the priority of the job is low (as with nice). The difference between nice and nohup is principally that a job run with nice will terminate when the user who invoked the job logs off.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck