Unix 3
Unix 3
Process:
• Process is a program under execution.
• It is an instance of an executing program, including the current values of
the pro- gram counter, registers & variables.
• Process is an abstraction of a running program.
Process Program
A process is program in execution. A program is set of instructions.
A process is an active/ dynamic entity. A program is a passive/ static entity.
A process has a limited life span. It is created when execution starts and
terminated as execution is finished. A program has a longer life span. It is
stored on disk forever.
A process contains various resources
like memory address, disk, printer etc… as per requirements. A program is
stored on disk in some file. It does not contain any other resource.
A process contains memory address which is called address space. A program requires
memory space on disk to store all instructions.
in (pseudo) parallel, than to try to keep track of how the CPU switches from
program to program.
• This rapid switching back and forth is called multiprogramming.
• In Fig. 2-2 (a) we see a computer multiprogramming four programs in memory.
• In Fig. 2-2 (b) we see four processes, each with its own flow of control
(i.e., its own logi- cal program counter), and each one running independently of
the other ones.
• There is only one physical program counter, so when each process runs, its
logical pro- gram counter is loaded into the real program counter.
• When it is finished for the time being, the physical program counter is saved
in the pro-
cess’ logical program counter in memory.
• In Fig. 2-2 (c) we see that over a long period of time interval, all the
processes have made progress, but at any given instant only one process is actually
running.
• With the CPU switching back and forth among the processes, the rate at which
a pro- cess performs its computation will not be uniform and probably not even
reproducible if the same processes are run again.
• Thus, processes must not be programmed with built-in assumptions about
timing.
Figure 2-2. (a) Multiprogramming of four programs. (b) Conceptual model of four
inde- pendent, sequential processes. (c) Only one program is active at once.
Process Creation
• There are four principal events that 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.
Process Termination
• After a process has been created, it starts running and does whatever its job
is.
• However, nothing lasts forever, not even processes. 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).
Process Hierarchies
• In some systems, when a process creates another process, the parent process
and child process continue to be associated in certain ways.
• The child process can itself create more processes, forming a process
hierarchy.
• An example of process hierarchy is in UNIX, which initializes itself when it
is started.
• A special process, called init, is present in the boot image.
• When it starts running, it reads a file telling how many terminals there are.
• Then it forks off one new process per terminal. These processes wait for
someone to log in.
• If a login is successful, the login process executes a shell to accept
commands. These commands may start up more processes, and so forth.
• Thus, all the processes in the whole system belong to a single tree, with
init at the root.
• In contrast, Windows does not have any concept of a process hierarchy. All
process- es are equal.
• The only identification for parent child process is that when a process is
created, the parent is given a special token (called a handle) that it can use to
control the child.
• However, it is free to pass this token to some other process, thus
invalidating the hierarchy. Processes in UNIX cannot disinherit their children.
• The process can be in any one of the following three possible states.
1) Running (actually using the CPU at that time and running).
2) Ready (runnable; temporarily stopped to allow another process run).
3) Blocked (unable to run until some external event happens).
• Once the process starts execution one of the following events could occur.
The process issues an I/O request and then be placed in an I/O queue.
The process creates a new sub process and wait for its termination.
The process is removed forcibly from the CPU and is put back in ready queue.
• A process switches from waiting state to ready state and is put back in ready
queue.
• The cycle continues unless the process terminates, at which the process is
removed from all queues and has its PCB and resources de-allocated.
Figure 2-6. Skeleton of what the lowest level of the operating system does when an
in- terrupt occurs.
• From here on, it is up to the software, in particular, the interrupt service
procedure.
• All interrupts start by saving the registers, often in the process table
entry for the cur- rent process.
• Then the information pushed onto the stack by the interrupt is removed and
the stack pointer is set to point to a temporary stack used by the process handler.
• When this routine is finished, it calls a C procedure to do the rest of the
work for this specific interrupt type.
• When it has done its job, possibly making some process now ready, the
scheduler is called to see who to run next.
• After that, control is passed back to the assembly language code to load up
the registers and memory map for the now-current process and start it running.
• Interrupt handling and scheduling are summarized in Figure 2-6.
(8) What is thread? Explain thread structure. Explain different types of thread.
OR Explain thread in brief.
Thread
• A program has one or more locus of execution. Each execution is called a
thread of execution.
• In traditional operating systems, each process has an address space and a
single thread of execution.
• It is the smallest unit of p