OS important concepts
Process
• A key concept in all operating systems is the process. A process is
basically a program in execution.
Address space
• Address space is associated with each Process
• Address space is a list of memory locations from 0 to some
maximum, which the process can read and write.
• The address space contains the executable program, the program’s
data, and its stack.
• Also associated with each process is a set of resources, commonly
including registers (including the program counter and stack pointer),
a list of open files, outstanding alarms, lists of related processes, and
all the other information needed to run the program.
• A process is fundamentally a container that holds all the information
needed to run a program.
Address space
• The address space of a process consists of all linear addresses that the
process is allowed to use. Each process sees a different set of linear
addresses; the address used by one process bears no relation to the
address used by another.
• kernel may dynamically modify a process address space by adding or
removing intervals of linear addresses.
• When the user types a command at the console, the shell process
creates a new process to execute the command. As a result, a fresh
address space, and thus a set of memory regions, is assigned to the
new process
Address space
• A running process may decide to load an entirely different program.
In this case, the process ID remains unchanged, but the memory
regions used before loading the program are released and a new set
of memory regions is assigned to the process
• Each section in the given address space is dedicated to performing a
specific task and is present to perform an explicit task. The most
common areas are the Kernel, program and program data, stack
value, heap value, and global data including shared libraries, shared
memory, or Dynamic Link Libraries.
Multiprogramming system
• The user may have started a video editing program and instructed it to
convert a one-hour video to a certain format (something that can take
hours) and then gone off to surf the Web. Meanwhile, a background
process that wakes up periodically to check for incoming email may
have started running.
Process Table
• Operating system decides to stop running one process and start
running another, perhaps because the first one has used up more than
its share of CPU time in the past second or two.
• All the information about each process, other than the contents of its
own address space, is stored in an operating system table called the
process table, which is an array of structures, one for each process
currently in existence.
System calls
• The key process-management system calls are those dealing with the
creation and termination of processes.
• The user has just typed a command requesting that a program be
compiled. The shell must now create a new process that will run the
compiler. When that process has finished the compilation, it executes
a system call to terminate itself.
• The Shell is the command line interpreter. It provides an interface
between the user and the kernel and executes programs called
commands.
Child processes
• If a process can create one or more other processes (referred to as
child processes) and these processes in turn can create child processes,
we quickly arrive at the process tree structure.
Inter process communication
• Related processes that are cooperating to get some job done often need
to communicate with one another and synchronize their activities. This
communication is called inter process communication
UID (User Identification)
• Every process started has the UID of the person who started it. A child
process has the same UID as its parent. Users can be members of
groups, each of which has a GID (Group Identification).
• One UID, called the superuser (in UNIX), or Administrator (in
Windows),has special power and may override many of the protection
rules.
Process and threads
Processes
• All modern computers often do several things at the same time.
• In any multiprogramming system, the CPU switches from process to
process quickly, running each for tens or hundreds of milliseconds.
While, strictly speaking, at any one instant the CPU is running only
one process, in the course of 1 second it may work on several of
them, giving the illusion of parallelism.
• operating system designers over the years have evolved a conceptual
model (sequential processes) that makes parallelism easier to deal
with.
The Process Model
• Process is just an instance of an executing program, including the
current values of the program counter, registers, and variables.
• The rapid switching back and forth among the processes is called
multiprogramming.
• In this chapter, we will assume there is only one CPU. That
assumption is not true, since new chips are often multicore, with two,
four, or more cores.
Difference b/w process and program
• The key idea here is that a process is an activity of some kind. It has a
program, input, output, and a state. A single processor may be shared
among several processes, with some scheduling algorithm being
accustomed to determine when to stop work on one process and
service a different one. In contrast, a program is something that may
be stored on disk, not doing anything.
Process creation
Four principal events cause processes to be created:
1. System initialization.
2. Execution of a process-creation system call by a running process.
3. A user request to create a new process.
4. Initiation of a batch job.
Technically, in all these cases, a new process is created by having an
existing process execute a process creation system call.
Process creation in UNIX is fork and in window with function call
CreateProcess
Process Termination
Sooner or later the new process will terminate, usually due to one of
the following conditions:
1. Normal exit (voluntary).
2. Error exit (voluntary).
3. Fatal error (involuntary).
4. Killed by another process (involuntary).
When a compiler has compiled the program given to it, the compiler
executes a system call to tell the operating system that it is finished.
This call is exit in UNIX and ExitProcess in window
Fatal error
• The second reason for termination is that the process discovers a fatal
error. For example, if a user types the command cc foo.c to compile
the program foo.c and no such file exists, the compiler simply
announces this fact and exits.
Process states
The three states a process may be in:
1. Running (actually using the CPU at that instant).
2. Ready (runnable; temporarily stopped to let another process run).
3. Blocked (unable to run until some external event happens).
Process scheduler
• Transitions 2 and 3 are caused by the process scheduler, a part of the
operating system, without the process even knowing about them.
• Transition 2 occurs when the scheduler decides that the running
process has run long enough, and it is time to let another process
have some CPU time.
• Transition 3 occurs when all the other processes have had their fair
share and it is time for the first process to get the CPU to run again.
• Transition 4 occurs when the external event for which a process was
waiting (such as the arrival of some input) happens.