Está en la página 1de 6

GeeksforGeeks

A computer science portal for geeks

Custom Search
search
Practice GATE CS Placements Videos Contribute

Login/Register
Skip to content
Algo DS Languages Interview Students GATE CS Subjects
Quizzes GBlog Puzzles Whats New?

Quick Links for Operating Systems


Recent Articles
MCQ / Quizzes
Practice Problems
Last Minute Notes (LMNs)

Basics
What happens when we turn on computer?
Explore More...
Processes & Threads
Process - Introduction
Thread
User Level thread vs. Kernel Level thread
Zombie Processes and their Prevention
Maximum number of Zombie process a system can handle
Maximum number of threads that can be created within a process in C
What exactly Spooling is all about?
Multi threading models
Explore More...
Process Synchronization
Introduction & Critical Section
Inter Process Communication
Mutex vs Semaphore & Monitors
Petersons Algorithm for Mutual Exclusion | Set 1 & Set 2
Readers-Writers Problem
Priority Inversion : What the heck !
Bankers Algorithm & Program
Priority Inversion vs. Priority Inheritance
Explore More...
CPU Scheduling
Process Management - Introduction
CPU Scheduling & Process Scheduler
FCFS Scheduling | Set 1 & Set 2
SJF scheduling
Round Robin scheduling
Priority Scheduling
Explore More...
Deadlocks
Introduction
Detection And Recovery
Prevention And Avoidance
Explore More...
Memory Management
Partition Allocation Method
Virtual Memory
Paging
Segmentation
Page Replacement Algorithms
Static and Dynamic Libraries
Working with Shared Libraries | Set 1 & Set 2
Explore More...
File & Disk Management
File System
File Allocation Methods
Disk Scheduling Algorithms
Explore More...
Linux
Linux File Hierarchy Structure
Initializing and Cache Mechanism in Linux Kernel
Some useful Linux Hacks
Explore More...
Operating System | Process Management | Introduction
Program vs Process
A process is a program in execution. For example, when we write a program in C or
C++ and compile it, compiler creates a binary code. The original code and Binary
code, both are programs. When we actually run the binary code, it becomes a
process.

A process is an active entity as oppose to program which considered to be a


passive entity. A single program can create many processes when run multiple
times, for example when we open an exe or binary file multiple times, many
instances begin (many processes are created).

How Does a process looks in Memory?


process

Text Section: Process is also sometime known as the Text Section.It also includes
the current activity represented by the value of Program Counter.
Stack: Stack contains the temporary data such as function parameters, return
address and local variables.
Data Section: Contains the global variable.
Heap Section: Dynamically allocated memory to process during its run time.
Refer this for more details of sections.

Attributes or Characteristics of a Process


A process has following Attributes.

1. Process Id: A unique identifier assigned by operating system


2. Process State: Can be ready, running, .. etc
3. CPU registers: Like Program Counter (CPU registers must be saved and
restored when a process is swapped out and in of CPU)
5. Accounts information:
6. I/O status information: For example devices allocated to process,
open files, etc
8. CPU scheduling information: For example Priority (Different processes
may have different priorities, for example
a short process may be assigned low priority
in shortest job first scheduling)
All the above attributes of a process are also known as Context of the process.
Every Process has its known Program control Block(PCB) i.e each process will have a
unique PCB. All the Above Attributes are the part of the PCB.
States of Process:
A process is in one of the following states

1. New: Newly Created Process (or) being created process.

2. Ready: After creation Process moves to Ready state, i.e.,


process is ready for execution.

3. Run: Currently running process in CPU (only one process at


a time can be under execution in a single processor).

4. Wait (or Block): When process request for I/O request.

5. Complete (or Terminated): Process Completed its execution.

6. Suspended Ready: When ready queue becomes full, some processes


are moved to suspend ready state

7. Suspended Block: When waiting queue becomes full.


process-states

Context Switching
Process of saving the context of one process and loading the context of other
process is known as Context Switching. In simple term it is like loading and
unloading of process from running state to ready state.

When does Context switching happen?


1. When a high priority process comes to ready state, compared to priority of
running process
2. Interrupt Occurs
3. User and Kernel mode switch: (It is not necessary though)
4. Preemptive CPU scheduling used.

Context Switch vs Mode Switch


A mode switch occurs when CPU privilege level is changed, for example when a system
call is made or a fault occurs. The kernel works in more privileged mode than a
standard user task. If a user process wants to access things which are only
accessible to kernel, a mode switch must occur. The currently executing process
need not to be changed during a mode switch.
A mode switch typically occurs for a process context switch to occur. Only the
Kernel can cause a context switch.

CPU Bound vs I/O Bound Processes:


A CPU Bound Process requires more amount of CPU time or spends more time in the
running state.
I/O Bound Process requires more amount of I/O time and less CPU time. I/O Bound
process more time in the waiting state.

Exercise:
1. Which of the following need not necessarily be saved on a context switch between
processes? (GATE-CS-2000)
(A) General purpose registers
(B) Translation look aside buffer
(C) Program counter
(D) All of the above
Answer (B)

Explanation:
In a process context switch, the state of the first process must be saved somehow,
so that, when the scheduler gets back to the execution of the first process, it can
restore this state and continue.The state of the process includes all the registers
that the process may be using, especially the program counter, plus any other
operating system specific data that may be necessary.A Translation look-aside
buffer (TLB) is a CPU cache that memory management hardware uses to improve virtual
address translation speed. A TLB has a fixed number of slots that contain page
table entries, which map virtual addresses to physical addresses. On a context
switch, some TLB entries can become invalid, since the virtual-to-physical mapping
is different. The simplest strategy to deal with this is to completely flush the
TLB.

2. The time taken to switch between user and kernel modes of execution be t1 while
the time taken to switch between two processes be t2. Which of the following is
TRUE? (GATE-CS-2011)
(A) t1 > t2
(B) t1 = t2
(C) t1 < t2
(D) nothing can be said about the relation between t1 and t2.

Answer: (C)
Explanation: Process switching involves mode switch. Context switching can occur
only in kernel mode.

Quiz on Process Management

References:
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/3_Processes.html
http://cs.nyu.edu/courses/spring11/G22.2250-001/lectures/lecture-04.html

Please write comments if you find anything incorrect, or you want to share more
information about the topic discussed above

GATE CS Corner Company Wise Coding Practice

Operating Systems CPU SchedulingGATE


Recommended Posts:

Operating System | Process Management | CPU Scheduling


What happens when we turn on computer?
Operating System | Process Scheduler
Operating System | Thread
Commonly Asked Operating Systems Interview Questions | Set 1

Post navigation<< Previous PostNext Post >>


(Login to Rate and Mark)

1.5 Average Difficulty : 1.5/5.0


Based on 6 vote(s)

Add to TODO List


Mark as DONE

Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share
the link here.

Load Comments
Share this post!

Trending Content
Implementing our Own Hash Table with Separate Chaining in Java
Print a Binary Tree in Vertical Order | Set 1
Find the k most frequent words from a file
Amazon Interview Experience | Set 161 (Off Campus for SDE-1, Banglore)
Median of two sorted arrays of different sizes
QA ? Placement Quizzes | Algebra | Question 10
Amazon Interview Experience | Set 339 (For SDE 2)
GATE | GATE CS 2013 | Question 6
Print Ancestors of a given node in Binary Tree
Pattern Searching | Set 8 (Suffix Tree Introduction)
ProGeek Cup 1.0

Most Visited Posts


Top 10 Algorithms and Data Structures for Competitive Programming
Top 10 algorithms in Interview Questions
How to begin with Competitive Programming?
Step by Step Guide for Placement Preparation
How to prepare for ACM-ICPC?
Insertion Sort, Binary Search, QuickSort, MergeSort, HeapSort

ads by BSA
Popular Categories
Interview Experiences
Advanced Data Structures
Dynamic Programming
Greedy Algorithms
Backtracking
Pattern Searching
Divide & Conquer
Geometric Algorithms
Searching
Sorting
Analysis of Algorithms
Mathematical Algorithms
Randomized Algorithms
Recursion
Game Theory
Tags
Advanced Data Structure Amazon Aptitude Aptitude Arrays Bit Magic C C C++ C++ Quiz
CPP-Library C Quiz Data Structures Data Structures DBMS Dynamic Programming
Experienced GATE-CS-2012 GBlog Graph Hash Internship Interview Experiences Java
java- Java Quiz Linked Lists Mathematical Matrix MCQ Microsoft number-digits
Program Output Project Puzzles Python QA - Placement Quizzes QA - Placement Quizzes
School Programming Searching Sorting STL Strings Technical Scripter Trees
Advertise Here
Recent Comments
@geeksforgeeks, Some rights reserved Contact Us! About Us!
Advertise with us! Privacy Policy
xLearn MoreReal time messaging, file sharing and powerful search. Slack: where work
happens.

También podría gustarte