0% found this document useful (0 votes)
91 views7 pages

Os Lec 4 Process

A process is an instance of a running program. It includes the program code, current activity, process stack, data section, and possibly a heap. A program becomes a process when loaded into memory. An operating system supports multiple concurrent processes through multiprogramming and multiprocessing. Multiprogramming allows multiple processes to run simultaneously by rapidly switching between them. Multiprocessing allows parallel processing across multiple CPUs. Each process is represented in the OS by a process control block containing its state, resources, and scheduling information. Processes transition between states like new, ready, running, waiting, and terminated. They are created through system calls or forks and terminated normally or abnormally.

Uploaded by

fihava5658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views7 pages

Os Lec 4 Process

A process is an instance of a running program. It includes the program code, current activity, process stack, data section, and possibly a heap. A program becomes a process when loaded into memory. An operating system supports multiple concurrent processes through multiprogramming and multiprocessing. Multiprogramming allows multiple processes to run simultaneously by rapidly switching between them. Multiprocessing allows parallel processing across multiple CPUs. Each process is represented in the OS by a process control block containing its state, resources, and scheduling information. Processes transition between states like new, ready, running, waiting, and terminated. They are created through system calls or forks and terminated normally or abnormally.

Uploaded by

fihava5658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROCESSES AND THREADS

PROCESSES

A process is a program in execution. A process is more than the program code, which is
sometimes known as the text section. It also includes the current activity, as represented by the
value of the program counter and the contents of the processor's registers. A process generally
also includes the process stack, which contains temporary data (such as function parameters,
return addresses, and local variables), and a data section, which contains global variables. A
process may also include a heap, which is memory that is dynamically allocated during process
run time.

Programs and Processes


A process is different than a program.

Consider the following analogy

Scenario-1: A computer scientist is baking a birthday cake for his daughter


Computer scientist - CPU
Birthday cake recipe - program
Ingredients - input data
Activities: - processes
reading the recipe
fetching the ingredients
baking the cake

Scenario-2: Scientist's son comes running in crying, saying he has been stung by a bee.
Scientist records where he - the state of running process was in the recipe saved
Reach first aid book and materials - Another process fetched
Follow the first aid action - Processor switched for new (high priority job) process
On completion of aid, cake - Completion of high priority baking starts again from job & return
back to the last one where it was left
A process is an activity of some kind, it has program, input, output and state.

Process Models
 Uniprogramming
 Multiprogramming
 Multiprocessing
Uniprogramming
Only one process at a time.

Examples: Older systems


Advantages: Easier for OS
designer

Disadvantages: Not convenient for user and


poor performance

Multiprogramming: Multiple processes at a time.


OS requirements for multiprogramming:
 Policy: to determine which process is to schedule.

 Mechanism to switch between the processes.

Examples: Unix , Wind


owsNT
Advantages: Better system
performance and user convenience.
Disadvantages: Complexity in OS,
Context Switching

Multiprocessing: System with multiple processors. Parallel Processing


Structure of a process

We emphasize that a program by itself is not a


process; a program is a passive entity, such as a file
containing a list of instructions stored on disk (often
called an executable file), whereas a process is an
active entity, 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 memory.

Two common techniques for loading executable files are double-clicking an icon representing
the
executable file and entering the name of the executable file on the command line (as in prog. exe
or a.
out.)
Process State
As a process executes, it changes state. The state of a process is defined in part by the current
activity of that process. Each process may be in one of the following states:
• New. The process is being created.
• Running. Instructions are being executed.
• Waiting. The process is waiting for some event to occur (such as an I/O completion or
reception of a signal).
• Ready. The process is waiting to be assigned to a processor.
• Terminated. The process has finished execution.

These names are arbitrary, and they vary across operating systems. The states that they represent
are footing on all systems, however. Certain operating systems also more finely delineate process
states. It is important to realize that only one process can be running on any processor at any
instant

Process Control Block


Each process is represented in the operating system by a process control block (PCB)—also
called a task control block
Process state. The state may be new, ready, running,
and waiting, halted, and so on. Program counter-The
counter indicates the address of the next instruction to
be executed for this process.
• CPU registers- The registers vary in number and
type, depending on the computer architecture. They
include accumulators, index registers, stack pointers,
and general-purpose registers, plus any condition code
information.
CPU-scheduling information- This information
includes a process priority, pointers to scheduling
queues, and any other scheduling parameters.
Memory-management information- This
information may include such information as the
value of the base and limit registers, the page tables, or the segment tables, depending on the
memory system used by the operating system
Accounting information-This information includes the amount of CPU and real time used, time
limits, account members, job or process numbers, and so on.
I/O status information-This information includes the list of I/O devices allocated to the process,
a list of open files, and so on.

Operations on Processes
The processes in the system can execute concurrently, and they must be created and
deleted dynamically. OS provide the mechanism for process creation and termination.

 Process Creation.
 Process Termination.
Process Creation
There are four principal events that cause the process to be created:
 System initialization.
 Execution of a process creation system call.
 User request to create a new process.
 Initiation of a batch job.

A process may create several new processes during the course of execution. The creating process
is called a parent process, where as the new processes are called children of that process

Two ways to create a new process

1. Build a new one from scratch

- Load specified code and data into memory.


- Create and initialize PCB.
- Put processes on the ready list.
2. Colon an existing one (e.g. Unix fork() syscall)

- Stop the current process and save its state.


- Make copy of code, data, stack, and PCB.
- Add new process PCB to ready list.

Unix Process Creation Ex.


#include<stdio.h>

int main(int argc, char *argv[])


{
int pid; pid = fork();/ * create new process */
if(pid < 0) { /* error occurred */
fprintf(stderr, “fork failed”);
exit(-1);
}
else if(pid == 0)
{ /*child process */
execlp(“/bin/ls”, “ls”,Null);
}
else
{ /* parent process */
wait(Null);
printf(“Child Complete”);
exit(0);
}

return 0;
}

Process Termination
Process are terminated on the following conditions

1. Normal exit.
2. Error exit.
3. Fatal error.
4. Killed by another process.

Example:
In Unix the normal exit is done by calling a exit system call. The process return data (output) to
its parent process via the wait system call. kill system call is used to kill other process

You might also like