Chapter 1. Operating System Basics: Q. Define Operating System. Explain Its Main Functions
Chapter 1. Operating System Basics: Q. Define Operating System. Explain Its Main Functions
An Operating System (OS) is a system software that acts as an interface between the user and the
computer hardware. It manages the computer's hardware resources and provides essential services
for computer programs. In simple terms, it controls and coordinates the use of hardware among
various application programs and users.
1. Process Management
• Ensures efficient CPU utilization through techniques like multitasking, multiprocessing, and
multithreading.
2. Memory Management
• Controls and coordinates input/output (I/O) devices like keyboards, printers, and disks.
• Protects data and resources through authentication (user login) and authorization
(permissions).
• Prevents unauthorized access using firewalls, encryption, and user roles.
• Handles protocols like TCP/IP, HTTP, FTP for internet and local network communication.
• Distributes CPU time, memory, and I/O devices among competing processes.
In summary, an operating system is essential for managing system resources, ensuring smooth
operation, and providing a user-friendly environment for users and applications.
Q. What are system calls? Describe their types with examples
System calls are the programming interface between the operating system and user-level
programs. They allow user applications to request services from the kernel of the operating system,
such as file operations, process control, device handling, etc.
Since user programs cannot directly access hardware or kernel data structures for protection and
stability reasons, system calls act as a controlled gateway to access these services.
System calls are broadly categorized into five main types, based on the services they provide:
1. Process Control:
Examples:
2. File Management:
Used for file operations like creation, deletion, reading, and writing of files.
Examples:
3. Device Management:
Examples:
4. Information Maintenance:
Examples:
5. Communication:
Used to establish communication between processes either on the same system or over a network.
Examples:
Summary:
System calls are essential for performing tasks that require direct interaction with the operating
system. They provide a safe and controlled way for user programs to utilize the services offered by
the OS kernel
2. Process Management & Scheduling
A process goes through different states during its lifetime. The operating system manages the
transitions between these states to ensure proper execution and resource utilization.
1. New:
The process is being created.
2. Ready:
The process is waiting to be assigned to a processor (CPU).
3. Running:
The process is currently being executed by the CPU.
4. Waiting (Blocked):
The process is waiting for some event to occur (like I/O completion).
5. Terminated (Exit):
The process has completed execution or has been terminated.
• Ready → Running:
The scheduler selects a process from the ready queue and assigns the CPU to it.
• Running → Waiting:
If the process requests an I/O operation or waits for some event, it is moved to the Waiting
state.
• Running → Ready:
If the running process is preempted (e.g., time slice ends in a time-sharing system), it returns
to the Ready state.
• Waiting → Ready:
Once the I/O or event is completed, the process goes back to the Ready queue.
• Running → Terminated:
When the process finishes execution or is killed, it moves to the Terminated state.
Conclusion:
These process states and transitions are essential for multitasking and resource sharing. The
operating system constantly monitors and controls these states to ensure smooth and efficient
process management
Q: Explain Process Control Block (PCB) and its contents.
The Process Control Block (PCB) is a data structure maintained by the Operating System for every
process. It contains all the information about a specific process that is required for process
management.
Whenever a context switch occurs (i.e., when the CPU switches from one process to another), the
OS saves the state of the current process in its PCB and loads the state of the next process from its
PCB.
Contents of PCB:
1. Process ID:
A unique identifier assigned to every process.
2. Process State:
Indicates the current state of the process (New, Ready, Running, Waiting, or Terminated).
3. Process Priority:
Determines the priority level of the process for scheduling purposes.
4. Accounting Information:
Keeps track of resource usage statistics like CPU time, memory usage, time limits, etc.
5. Program Counters:
Stores the address of the next instruction to be executed.
6. CPU Registers:
Includes all general-purpose registers, stack pointers, etc., required for process execution.
7. PCB Pointers:
Pointers to other PCBs, used in managing process queues and hierarchies (e.g., child or
parent processes).
Conclusion:
The PCB plays a vital role in context switching and process management. It allows the operating
system to resume a process exactly where it left off by storing all essential details. Each running
process has its own PCB, and the OS uses these blocks to manage multitasking effectively.
Q. Compare FCFS, SJF (preemptive/non-preemptive), Priority, and Round Robin
scheduling.
Q.: What is context switching? Describe kernel actions.
Context switching is the process by which the operating system saves the state of a currently
running process and loads the state of another process so that execution can continue from the
point it was paused.
It occurs during multitasking when the CPU switches from one process or thread to another,
enabling multiple processes to share a single CPU efficiently.
Diagram (Text-based):
• To support multitasking/multiprocessing
• Process State
• Stack Pointer
• The CPU state (registers, PC, stack pointer, etc.) of the currently running process is saved
into its Process Control Block (PCB).
• The process state is changed from Running to Ready or Waiting depending on the reason
for the switch.
• The CPU scheduler selects the next process to run based on the scheduling algorithm (e.g.,
FCFS, SJF, Round Robin).
• The CPU registers, PC, and other information are loaded from the new process’s PCB.
• The kernel returns control to the user space of the new process, and it begins/resumes
execution.
Conclusion:
Context switching is essential for efficient CPU utilization and system responsiveness. However, it
introduces overhead, since saving and loading states takes time without performing useful
computation during the switch. Efficient OS design aims to minimize context switching while
maintaining fairness and responsiveness.
Q. Difference between process and thread (give in columns)
Has its own separate memory Shares memory space with other threads
Address Space
space in the same process
One process crashing does not One thread crashing can affect the entire
Crash Impact
affect others process