Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Privileged and Non-Privileged Instructions in Operating System
Next article icon

Privileged and Non-Privileged Instructions in Operating System

Last Updated : 08 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In an operating system, instructions executed by the CPU can be classified into privileged and non-privileged instructions. These classifications help the operating system ensure security, stability, and efficient resource management. In this article, we will discuss Privileged and Non-Privileged Instructions in Operating Systems.

What are Privileged Instructions? 

Privileged instructions are those that can only be executed by the operating system kernel or a privileged process, such as a device driver. These instructions typically perform operations that require direct access to hardware or other privileged resources, such as setting up memory mappings or accessing I/O devices. The Instructions that can run only in Kernel Mode are called Privileged Instructions. Privileged Instructions possess the following characteristics:

  • If any attempt is made to execute a Privileged Instruction in User Mode, then it will not be executed and treated as an illegal instruction. The Hardware traps it in the Operating System. 
  • Before transferring the control to any User Program, it is the responsibility of the Operating System to ensure that the Timer is set to interrupt. Thus, if the timer interrupts then the Operating System regains control. 
  • Thus, any instruction which can modify the contents of the Timer is Privileged Instruction. 
  • Privileged Instructions are used by the Operating System to achieve correct operation. 
  • Various examples of Privileged Instructions include:  
    • I/O instructions and Halt instructions
    • Turn off all Interrupts
    • Set the Timer
    • Context Switching
    • Clear the Memory or Remove a process from the Memory
    • Modify entries in the Device-status table

Role of OS in managing Privileged Instructions

  • Access control: The operating system employs access control mechanisms to limit access to privileged instructions. These mechanisms are restricted to authorized processes or users with elevated privileges. This guarantees that privileged instructions can only be executed by trusted processes and thwarts unauthorized access of malicious programs to system resources.
  • Memory protection: By deploying memory protection techniques, the operating system restricts processes from accessing any memory location that belongs to it or other processes. This aids in preventing tampering with the operating system or other processes by ensuring that processes cannot do so. Furthermore, it hinders malevolent programs from resulting in system crashes or risking the system's safety.
  • Interrupt handling: The execution of privileged instructions like system calls or exceptions is handled by the operating system through interrupt handling to ensure safety and accuracy, so when an interrupt occurs during the execution of a process it's necessary to save its state before transferring control to a suitable handler and then restoring it on completion.
  • Virtualization: Using virtualization techniques allows the operating system to create a simulated environment where processes can execute privileged instructions without having direct access to the underlying hardware thus creating a more secure and isolated execution environment for privileged instructions by limiting process access to authorized hardware resources only.

What are Non-Privileged Instructions? 

Non-privileged instructions are those that can be executed by any process, including user-level processes. These instructions are typically used for performing computations, accessing user-level resources such as files and memory, and managing process control. Non-privileged instructions are executed in user mode, which provides limited access to system resources and ensures that processes cannot interfere with one another. The Instructions that can run only in User Mode are called Non-Privileged Instructions .

 Various examples of Non-Privileged Instructions include: 

  • Reading the status of Processor
  • Reading the System Time
  • Generate any Trap Instruction
  • Sending the final printout of Printer

Also, it is important to note that in order to change the mode from Privileged to Non-Privileged, we require a Non-privileged Instruction that does not generate any interrupt. 

Differences Between Privileged and Non-Privileged Instructions

CriteriaPrivileged InstructionsNon-Privileged Instructions
Access to ResourcesDirect access to system resourcesLimited access to system resources
Execution ModeExecuted in kernel modeExecuted in user mode
Execution PermissionsRequire special permissions to executeDo not require special permissions to execute
PurposeUsed for performing low-level system operationsUsed for general-purpose computing
RisksHigher risk of causing system crashes or security vulnerabilitiesLess risky in terms of system crashes or security vulnerabilities

Advantages of Privileged and Non-Privileged Instructions

  • Security: This ensures that unauthorized persons do not access resources of their system. The operating system or other trusted processes can only execute privileged instructions while user programs can run non-privileged instructions.
  • Performance: This reduces overhead and latency by allowing them to access hardware resources directly.
  • Stability: Non-privileged instructions are limited in accessing system resources while privileged instructions can only be executed by trusted processes. The distinction between user programs and critical system functions keeps any harm caused by the user program at bay.
  • Flexibility: Operating systems support a variety of applications and hardware devices because they have both types of instructions. Developers find it easy to create new applications and hardware through an interface defined within the operating system for compatibility purposes.
  • Debugging: With a clear demarcation between trusted and untrusted processes, this makes it easier to debug the operating system itself plus the applications running on top of it. To resolve issues, developers must identify them first which is made possible through this separation.

Disadvantages of Privileged and Non-Privileged Instructions

  • Overhead: Instructions that are either privileged or non-privileged can have an impact on overhead as well as performance degradation. Changes between the two modes, privileged and non-privileged ones, may take long time causing the system performance to drop.
  • Complexity: Operating systems using such instructions with distinct access levels (privileged or non-privileged) become extremely complex and challenging to develop and maintain. The necessity of both types of instructions makes it even harder to design system features and ensure system stability.
  • Compatibility: Privileged and non-privileged instructions may bring compatibility problems among different hardware platforms or operating systems. Diverse implementations of privileged instructions make it hard for creation of applications working on various platforms.
  • Vulnerabilities: These resources are targeted by attackers who exploit security flaws in the operating system.

Conclusion

Privileged instructions are used by the operating system kernel and privileged processes to perform low-level system operations, while non-privileged instructions are used by user-level processes for general-purpose computing. The distinction between privileged and non-privileged instructions is an important mechanism for ensuring the security and stability of an operating system.


Next Article
Privileged and Non-Privileged Instructions in Operating System

R

RishabhJain12
Improve
Article Tags :
  • Operating Systems
  • GATE CS

Similar Reads

    Special Machine Instructions in Operating System
    Machine instructions are machine code programs or commands. In other words, commands written in the machine code of a computer that it can recognize and subsequently execute. Machine code or machine language refers to a computer programming language consisting of a string of ones and zeros, i.e., bi
    4 min read
    Instruction Execution in Operating System
    Instruction execution in an operating gadget refers to the process by which the central processing unit (CPU) of a computer device carries out commands provided by means of walking applications or strategies. The operating machine plays an essential position in managing and coordinating this trainin
    3 min read
    Design and Implementation in Operating System
    The design of an operating system is a broad and complex topic that touches on many aspects of computer science. This article will cover the design of operating systems in general and then focus on the implementation aspect. Design Goals:Design goals are the objectives of the operating system. They
    6 min read
    Process Creation and Deletions in Operating Systems
    A process is an instance of a program running, and its lifecycle includes various stages such as creation, execution, and deletion. The operating system handles process creation by allocating necessary resources and assigning each process a unique identifier. Process deletion involves releasing reso
    6 min read
    Need and Functions of Operating Systems
    The fundamental goal of an Operating System is to execute user programs and to make tasks easier. Various application programs along with hardware systems are used to perform this work. Operating System is software that manages and controls the entire set of resources and effectively utilizes every
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences