Thursday, March 5, 2009

Multitasking Definition

Multitasking refers to an operating system in which multiple processes, also called tasks, can execute (i.e., run) on a single computer seemingly simultaneously and without interfering with each other. That is, each process has the illusion that it is the only process on the computer and that it has exclusive access to all the services of the operating system.

The concurrently running processes can represent different programs, different parts of a single program and different instances of a single program. The total number of processes (or programs) that can run on the system at any time depends on several factors including the size of the memory, the speed of the CPU (central processing unit) and the size of the programs.

All processes are fully protected from each other, just as the kernel (i.e., the core of an operating system) on a well-designed system is protected from all processes, so that a crash (i.e., a halt to functioning) in one process or program will not cause another program or the entire system to crash. However, processes communicate with each other when necessary.

The CPU (or CPUs if there are more than one) is continuously in demand by the typically numerous processes that are competing for its services. But because a CPU can execute only one process at a time, multitasking is accomplished through the use of a time slice technique that alternates its use at extremely high speeds among the various processes.

In unitasking operating systems, such as MS-DOS, the CPU remains idle until the system resource that a process desires (such as a disk drive or printer) becomes available, thus wasting processor time and reducing system efficiency. In a multitasking system, however, multiple processes are retained in the main memory, which physically consists of RAM (i.e., random access memory) chips, so that whenever one process has to wait, the operating system can immediately allocate the CPU to other processes.

Origins of Multitasking

Multitasking originated in the 1960s, when time sharing systems were developed to enable multiple users to share single, and very costly, mainframe computers. It soon became apparent that a similar technique could also be used to allow a single user to simultaneously run multiple application programs. The term time sharing was subsequently replaced by the more general term multitasking.

On early multitasking systems, groups of related application programs voluntarily relinquished the CPU to each other in what is referred to as cooperative multitasking. One disadvantages of that approach is that the scheduler cannot make system-wide decisions as to how long each process should run, which can result in the inefficient use of system resources. The scheduler is a part of the kernel that assigns priorities to processes in a priority queue.

Another disadvantage is that it can be more difficult to develop application programs for use on such operating systems. In addition, a poorly designed program or a crashed process can potentially crash the entire operating system because it could prevent a process from relinquishing the CPU to other processes.

Thus, cooperative multitasking evolved into preemptive multitasking, in which the hardware can interrupt an executing process and instruct the CPU to execute a different section of code. Such a system does not need to rely on the voluntary relinquishing of processor time by individual processes. Rather, it can be set to preempt currently running processes and return control to the operating system, which can later restore each preempted process in exactly the same state where it was interrupted. Preemption is the involuntary suspension of some running processes so that other processes can be executed.

Preemptive multitasking increases overall system efficiency by freeing up the CPU and other system resources when ordered to by the operating system on a time slice basis or a priority basis so that one application cannot monopolize system resources when they are needed by another program. It also permits the system to respond immediately to important external events, such as incoming data from a keyboard or network. Moreover, it simplifies the development of application programs and provides better program performance because processes can switch in and out of the processor with less overhead, i.e., with less and simpler code.

Multitasking is particularly crucial for real time operating systems (such as are used in embedded systems), for which it is necessary to monitor and control multiple external activities with a single processor virtually instantaneously. Such systems employ a hierarchical interrupt mechanism together with prioritization of processes to ensure that specified types of activities are granted an immediate and adequate slice of processor time.

Multitasking in Linux

Today most major operating systems employ multitasking. Earlier versions of the Macintosh and Microsoft Windows used cooperative multitasking. Preemptive multitasking operating systems include Linux and other Unix-like systems, Microsoft Windows NT/2000/XP, Mac OS X and OS/2.

Unix-like operating systems were developed right from the start as preemptive multitasking and multi-user systems. These are among the features that have helped make them an extremely efficient and robust (as well as highly successful and long-lived) family of operating systems. (They are also multiprocessor operating systems, which means that they can make effective use of computers that have more than a single CPU.)

Multiple processes exist for virtually the entire duration of a Linux session, even if no user application programs are running. The only exception is a very brief period during booting (i.e., starting up of a computer), when init, which is the first process to be created on a newly booted system, has not yet spawned additional processes.

Multitasking can be easily observed in Unix-like operating systems when the X Window System (i.e., the standard system for managing GUIs on single computers and on networks of computers) is used. That is, multiple windows can be simultaneously open on the display screen, each with an application program running independently of the others. The independence of these applications is evidenced by the fact that, as experienced Linux users are well aware, even if one of the applications crashes, it is very rare that it will cause other applications to malfunction or cause the system as a whole to crash (and thus require rebooting).

While not quite as obvious, especially to new users, multitasking is also occurring when a Unix-like system is operating in console (i.e., text only) mode. That is, different programs can be operating on different virtual consoles. Moreover, multiple programs can also operate on a single console or terminal window (i.e., a window in a GUI that emulates console mode) by having one program run in the foreground while others are running in the background.
The full extent of processes currently residing on a can be seen by using the ps command with its -a, -u and -x options, i.e.,

ps -aux | less

As the number of processes can be quite long and occupy more than a single screen, this command uses a pipe (represented by the vertical bar) to transfer the output of ps -aux to the less command so that that it can be viewed one screenful at a time. The list of processes can be advanced one screen forward by pressing the SPACE bar and one screen backward by pressing the b key. An alternative way to view the processes is with the pstree command, which presents them in a tree diagram.

Several instances of a single program may be visible in the output from either of these commands. If they are not, a simple way to start two instances of a single program is to open a second terminal window. This results in another shell process being started. Repeating the above command will then show the processes for both instances of bash (which is the default shell on Linux) or whatever shell is being used.
 
Things You Should Know About Linux !!!