Process Management and Scheduling

All modern operating systems are able to run several processes at the same time — at least, this is the impression users get. If a system has only one processor, only one program can run on it at a given time. In multiprocessor systems, the number of processes that can truly run in parallel is determined by the number of physical CPUs.

The kernel and the processor create the illusion of multitasking — the ability to perform several operations in parallel — by switching repeatedly between the different applications running on the system at very rapid intervals. Because the switching intervals are so short, users do not notice the intervening brief periods of inactivity and gain the impression that the computer is actually doing several things at once.

This kind of system management gives rise to several issues that the kernel must resolve, the most important of which are listed below.

□ Applications must not interfere with each other unless this is expressly desired. For example, an error in application A must not be propagated to application B. Because Linux is a multiuser system, it must also be ensured that programs are not able to read or modify the memory contents of other programs — otherwise, it would be extremely easy to access the private data of other users.

□ CPU time must be shared as fairly as possible between the various applications, whereby some programs are regarded as more important than others.

I deal with the first requirement — memory protection — in Chapter 3. In the present chapter, I focus my attention on the methods employed by the kernel to share CPU time and to switch between processes. This twofold task is split into two parts that are performed relatively independently of each other.

□ The kernel must decide how much time to devote to each process and when to switch to the next process. This begs the question as to which process is actually the next. Decisions of this kind are not platform-dependent.

□ When the kernel switches from process A to process B, it must ensure that the execution environment of B is exactly the same as when it last withdrew processor resources. For example, the contents of the processor registers and the structure of virtual address space must be identical.

This latter task is extremely dependent on processor type. It cannot be implemented with C only, but requires help by pure assembler portions.

Both tasks are the responsibility of a kernel subsystem referred to as the scheduler. How CPU time is allocated is determined by the scheduler policy, which is totally separate from the task switching mechanism needed to switch between processes.

Continue reading here: Process Priorities

Was this article helpful?

0 0