-->
Previous Table of Contents Next


Chapter 19
Managing Multiple Processes

by Jack Tackett

In this chapter
Understanding Multitasking
Initiating Multiple Processes
Using the Scheduling Commands
Reporting On and Monitoring the Multitasking Environment
Controlling Multiple Processes

Linux is a multiuser and multitasking operating system. Multiuser means that several people can use the computer system simultaneously (unlike a single-user operating system, such as MS-DOS). Multitasking means that Linux, like Windows NT, can work on several tasks concurrently; it can begin work on one task and take up another before the first task is finished.

Taking care of several user requests and multitasking are the jobs of the operating system. Most systems have only one CPU and one collection of chips that make up main memory, or RAM. A system may have more than one disk or tape drive for secondary memory and several input/output devices. All these resources must be managed and shared between several users. The operating system creates the illusion that each user has a dedicated computer system.

Understanding Multitasking

As mentioned earlier, it’s Linux’s job to create the illusion that when you make a request, you have the system’s undivided attention. In reality, hundreds of requests may be handled between the time you press <Return> and the time the system responds to your command.

Imagine having to keep track of dozens of tasks simultaneously. You have to share the processing power, storage capabilities, and input and output devices among several users or several processes belonging to a single user. Linux monitors a list—also known as a queue—of tasks waiting to be done. These tasks can include user jobs, operating system tasks, mail, and background jobs such as printing. Linux schedules slices of system time for each task. By human standards, each time slice is extremely short—a fraction of a second. In computer time, a time slice is adequate for a program to process hundreds or thousands of instructions. The length of the time slice for each task may depend on the relative priority of each task.

Linux works on one task from the queue for a while, puts the task aside to begin work on another task, and so on. It then returns to the first task and works on it again. Linux continues these cycles until it finishes a task and takes the task out of the queue, or until the task is terminated. In this arrangement, sometimes called time-sharing, the resources of the system are shared among all the tasks. Naturally, time-sharing must be done in a reliable and efficient manner. The UNIX term for a task is process. Table 19.1 shows several types of processes.

Table 19.1 Types of Processes

Process Type Description

interactive Initiated by a shell and running in the foreground or background
batch Typically a series of processes scheduled for execution at a specified point in time
daemon Typically initiated at boot time to perform operating system functions on demand, such as LPD, NFS, and DNS

You’ve already seen that you can put or run a program in the background. While the program runs in the background, you can continue entering commands and working with other material. This is a feature of multitasking: Linux uses the time-sharing method to balance your immediate commands and the ones running in the background. This chapter shows other ways to schedule processes so that they can run without your attention (batch process).


See “Doing Background Processing,” p. 361

The Linux operating system has the primary responsibility of handling the details of working with several users and several processes. As a user, you have the power to specify which programs you want to run. Some Linux commands let you specify when you want a process to start. You also can monitor your processes as well as see what other processes are running. In some cases, you can change their relative priority. And you can always terminate your processes if the need arises. If you’re the system administrator, you have all these capabilities, plus the responsibility and power to initiate, monitor, and manage processes that belong to the operating system or any user.

Table 19.2 lists the commands that make it possible to control the multiuser and multitasking capabilities of Linux.

Table 19.2 Multiuser and Multitasking Commands

Command Action

at Executes commands at a given time
batch Executes commands when system load allows
cron Executes scheduled commands
crontab Maintains crontab files for individual users
kill Stops processes
nice Adjusts the priority of a process before it starts
nohup Allows a process to continue after you log out
ps Displays process information
renice Adjusts the priority of a running process
w Shows you who is logged in and what they’re doing
who Displays the system’s logged-in users


NOTE:  For more information on the commands in Table 19.2, you can consult the following man page:

man command

You also can use the –help option:


command –help


Initiating Multiple Processes

You can start running a program by entering its name. You can also start programs from files that contain shell commands. Running programs can interact with many different parts of the system. A program can read from or write to files, manage its information in RAM, or send information to printers, modems, or other devices. The operating system also attaches information to a process so that the system can keep track of and manage it.

A process is a running program, but is different from a program. In one sense, a process is more than a program because a program is only a set of instructions; a process is dynamic because it uses the resources of a running system. On the other hand, a single Linux program can start several processes.


Previous Table of Contents Next