đź“ŚProcess management
-
Process management describes the starting, pausing, resuming, scheduling, 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 can 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:
-
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.
-
The kernel records the current state of the CPU and memory, which will be essential to resuming the process that was just interrupted.
-
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).
-
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.
-
The kernel prepares the memory for this new process and then prepares the CPU.
-
The kernel tells the CPU how long the time slice for the new process will last.
-
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, as most current machines are, 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, and more than one process may run at a time. However, to maximize the usage of all available CPUs, the kernel typically performs these steps anyway (and may use certain tricks to grab a little more CPU time for itself).
đź“ŚProcess
-
Running instance of a program is called a PROCESS
-
If you have two terminal window showing on your screen then you are probably running the same terminal program twice-you have two terminal processes
-
ecah terminal window is probably running a shell; each running shell is another process
-
when you invoke a command from a shell, the corresponding program is executed in a new process
-
the shell process rumes when that process complete
đź“ŚProcess vs Program
-
A program is a passive entity ,such as file containining a list of instructions stored pm a disl
-
Process is a activeentity , with a program counter specifying the next instruction to execute and a set of associated resources
-
A program becomes a process when an executable file is loaded into main memory
factor | Process | Program |
---|---|---|
storage | Dynamic Memory | Secondary Memory |
State | Active | Passive |
WIP - Work in process