Process management describes the starting, pausing, resuming, and terminating of processes. The concepts behind starting and terminating processes are fairly straightforward, but describing how a process uses the CPU in its normal course of operation is a bit more complex.
On any modern operating system, many processes run "simultaneously." For example, you might have a web browser and a spreadsheet open on a desktop computer at the same time. However, things are not as they appear: The processes behind these applications typically do not run at exactly the same time.
Consider a system with a one-core CPU. Many processes may be able to use the CPU, but only one process may actually use the CPU at any given time. In practice, each process uses the CPU for a small fraction of a second, then pauses; then another process uses the CPU for another small fraction of a second; then another process takes a turn, and so on. The act of one process giving up control of the CPU to another process is called a context switch.
Each piece of time - called a time slice - gives a process enough time for significant computation (and indeed, a process often finishes its current task during a single slice). However, because the slices are so small, humans can't perceive them, and the system appears to be running multiple processes at the same time (a capability known as multitasking).
The kernel is responsible for context switching. To understand how this works, let's think about a situation in which a process is running in user mode but its time slice is up. Here's what happens:
1. The CPU (the actual hardware) interrupts the current process based on an internal timer, switches into kernel mode, and hands control back to the kernel.
2. The kernel records the current state of the CPU and memory, which will be essential to resuming the process that was just interrupted.
3. The kernel performs any tasks that might have come up during the preceding time slice (such as collecting data from input and output, or I/O, operations).
4. The kernel is now ready to let another process run. The kernel analyzes the list of processes that are ready to run and chooses one.
5. The kernel prepares the memory for this new process, and then prepares the CPU.
6. The kernel tells the CPU how long the time slice for the new process will last.
7. The kernel switches the CPU into user mode and hands control of the CPU to the process.
The context switch answers the important question of when the kernel runs. The answer is that it runs between process time slices during a context switch.
In the case of a multi-CPU system, things become slightly more complicated because the kernel doesn't need to relinquish control of its current CPU in order to allow a process to run on a different CPU. However, to maximize the usage of all available CPUs, the kernel typically does so anyway (and may use certain tricks to grab a little more CPU time for itself).
About the Author
Brian Ward has been working with Linux since 1993. He is the author of The Linux Kernel-HOWTO, The Book of VMware, and The Linux Problem Solver.
Unlike some operating systems, Linux doesn't try to hide the important bits from you - it gives you full control of your computer. But to truly master Linux, you need to understand its internals, like how the system boots, how networking works, and what the kernel actually does.
In this third edition of the bestselling How Linux Works, author Brian Ward peels back the layers of this well-loved operating system to make Linux internals accessible. This edition has been thoroughly updated and expanded with added coverage of Logical Volume Manager (LVM), virtualization, and containers.
You'll learn:
• How Linux boots, from boot loaders to init (systemd)
• How the kernel manages devices, device drivers, and processes
• How networking, interfaces, firewalls, and servers work
• How development tools work and relate to shared libraries
• How to write effective shell scripts
You'll also explore the kernel and examine key system tasks inside user-space processes, including system calls, input and output, and filesystem maintenance. With its combination of background, theory, real-world examples, and thorough explanations, How Linux Works, 3rd Edition will teach you what you need to know to take control of your operating system.
New to This Edition:
• Hands-on coverage of the LVM, journald logging system, and IPv6
• Additional chapter on virtualization, featuring containers and cgroups
• Expanded discussion of systemd
Reader Garret P. Arcoraci says, "I teach System Administration at the Rochester Institute of Technology; usually, I don't make a book a requirement, but this is the exception. Highly recommend it to anyone looking for a deeper understanding of the Linux operating system and traditional computer architecture."
More Windows Administration Information:
• How to Load or Unload a Linux kernel Module
• 12 Essential Linux Commands for Beginners
• Know linux
• Fedora 3 Modem Installation
• Connecting Linux to the Internet
• Fedora 3 Linux File Management
• What is Ubuntu?
• Installing Software on Fedora
• Linux Display Settings
• An introduction to the Linux Boot and Startup Processes