Lecture - 2
Lecture - 2
Process Management
Course out line
❑ Processes and Threads
➢ Process concept
➢ Inter-process Communication
✓ Classical IPC problems
➢ Process scheduling
➢ Deadlock
➢ Thread concept
➢ Single thread and multithread programming
❑ Basic process and thread management in Linux-creating,
monitoring, and killing processes and threads in Linux
Common OS System Components
▪ Process Management and CPU scheduling
▪ MM management
▪ File management
▪ I/O system management
▪ Secondary storage management
▪ Networking
▪ Protection system
▪ Command-Interpreter system
Process
✓ An instance of a program running on a computer.
✓ A process has its own address space, file handles,
security attributes, threads, etc.
✓ A process needs certain resources, including CPU
time, memory, file, and I/O devices, to accomplish its
task.
Process vs program
Process Program
Process is a dynamic object Program is a static object
It is sequence of It is a sequence of instructions
instruction execution
Process loaded in to main Program loaded into secondary
memory storage devices
Time span of process is Time span of program is unlimited
limited
Process is a active entity Program is a passive entity
Process Management
❑The OS is responsible for the following activities in
connection with process management.
✓Process communication
Creation of a process
▪ When a new process is added, OS builds various data
structures to manage the newly added process.
e.g. A printer server or file server may generate a new process for
each request that it handles.
Process Termination
✓Normal completion
✓Time limit exceeded: iteration process
✓Memory unavailable: the limit on max. no. of process
✓Bound violation: access to memory location
✓Protection error: writing to a read-only file
✓Arithmetic error: divide by zero
✓Time overrun: waiting for i/o for infinite time
✓i/o failure, invalid instruction, privileged instruction
✓OS intervention: deadlock occurs, parent termination, parent request
• A small dispatcher program is used to switch the processor from one
process to another.
Interactive user input: user wants to suspend the process for debugging
purposes.
Process state transition with suspended states
New Termination
Blocked → Blocked/Suspend
Blocked/Suspend → Ready/Suspend
Ready/Suspend → Ready
Ready → Ready/Suspend
New → Ready/Suspend and New – Ready
Blocked/Suspend → Blocked
Running → Ready/Suspend
Any state → exit
Characteristics of Suspended process
✓The process is not immediately available for execution.
✓If waiting and if the event takes place, the process cannot be
executed immediately.
• The process control block is the key tool that enables the OS to support
multiple processes and to provide for multiprocessing.
22
Process List structure
Process States …
• Any computer system must provide a means
for a process to indicate its completion.
✓ Computation speed-up
✓ Convenience
Inter-process Communication (IPC)
Why IPC
✓Each process has its own address space.
different process.
IPC mechanisms
In GRU/Linux
✓Signal
✓Pipe
✓Socket
✓Semaphore
✓Message queue
✓Shared memory
In android
✓Binder: lightweight RPC (Remote procedure
communication) mechanism.
Binder: Android’s solution
✓Driver to facilitate inter-process communication
37
• User Threads Kernel Thread
❑ Thread management done by ❑ Supported by the Kernel
41
Thread …
−Responsiveness
Benefits −Resource Sharing
− Economy
− Scalability
Types of Multiprocessor Systems:
48
SMP Architecture …
49
MICROKERNELS
• A microkernel is a small OS core that provides the foundation for
modular extensions.
• A microkernel is one of the classifications of the kernel. Being a
kernel it manages all system resources.
• But in a microkernel, the user services and kernel services are
implemented in different address spaces.
• The user services are kept in user address space, and kernel
services are kept under kernel address space, thus also reduces the
size of kernel and size of an operating system as well. 50
MICROKERNELS…
51
The microkernel is solely responsible for the most
important services of the operating system, these are:
• Inter process-Communication
• Memory Management
• CPU-Scheduling
The five main types of kernels are:
✓ Monolithic Kernel.
✓ Microkernel.
✓ Hybrid Kernel.
✓ Nano Kernel.
✓ Exo Kernel.
▪A Kernel in an operating system
performs the following functions:
✓ Device Management
✓ Resource Management
✓ Memory Management
✓ Access Computer Resource
Kernel vs Microkernel
• Kernel is a core feature of any operating system, the kernel manages
communication between hardware and software.
• The kernel is responsible for managing memory, and I/O to memory,
cache, the hard drive, and other devices.
• It also handles device signals, task scheduling, and other essential duties.
• The kernel is one of the first components loaded into memory during the
boot process, and remains active as long as the computer is operational.
• Kernels vary widely in function and scope, but always greatly affect their
operating system's capabilities.
• For this reason, particularly in Unix, administrators tweak the kernels to
best suit their requirements.
Kernel vs Microkernel
✓microkernel is compact, performing only the basic functions universal to
all computers.
✓Designed to be integrated into different operating systems, a microkernel
works with OS-specific servers that provide higher level functions.
✓This component-based structure improves a system's portability, but
potentially at the expense of performance.
✓ Mach and its derivatives, the most prominent examples of the
microkernel architecture, are the foundations of systems such as Tru64
Unix, the GNU Hurd, and Mac OS X.
Benefits of a Microkernel Organization
• Uniform interfaces
• Message Passing Facilities
• Extensibility
• Flexibility
• Portability
• Reliability
• Distributed system support
• Support for object-oriented operating systems (OOOSS)
58
Single thread and multithread programming
✓Single threaded processes contain the execution of instructions in a
single sequence, (one command is processes at a time).
70
71
Concurrency …
• In the case of competing processes three control problems must be faced.
receiving data.
72
For process scheduling operating system uses:
First Come First Serve (FCFS) Algorithm: which comes first is served first by
the CPU until it is completed. It is a non-preemptive algorithm which means it
cannot be terminated without completing it.
Shortest Job First (SJF) Algorithm: The process which has the shortest burst
time (execution time) that will be served first by the CPU.
Longest Job First (LJF) Algorithm: This algorithm is based on the
phenomenon that the process that has the longest execution time will be served
first by the processor.
For process scheduling operating system uses:
Round Robin Algorithm: In this algorithm, there is a specific time
quanta assigned for each process. If the process is not executed in
time quanta, it is sent to the waiting queue for its next turn.
Priority Scheduling Algorithm: Processes are given the priority
based on different criteria and scheduled according to the highest
priority. Criteria can be burst time or arrival time etc.
Basic process and thread management in:
- Linux-creating
- Linux-monitoring
- Linux-killing processes
- Threads in Linux
Linux Process and Thread Management
▪A process in LINUX is a single program running in its own virtual
space on the operating system.
▪To create a process in LINUX, the ‘parent process‘ initiate a fork().
▪Fork() suggests that the process creates a copy of itself.
▪A process in LINUX is represented by a data structure (like PCB) is
called ‘task-struct‘.
▪It contains the all information about the process.
LINUX Task Structure:
1. PID It specifies one of the 5 states of a process.
3. Scheduling Information: It specifies that which type of information needed.
4. Links: Process having the link to its parent process if it is a child process.
If it is a parent process links to all of its children.
5. File System: It includes pointers to any files opened by this process.
6. Virtual Memory: It defines the virtual memory assigned to this process.
7. Times and Timers: It specifies process creation time, CPU burst time of a process, etc.
8. Processor-specific context: The registers and stack information that constitute the
context of this process.
Process creation in Linux
Linux system call for creating process and thread
System calls
- write (), open(), dup(), read()
Process
- fork(), wait(), system(),
Thread, deadlock,
synchronization
- Mutex-lock
- semaphores
IPC – pipe(), popen()/pclose(), mkfifo(),and shared memory
Process in Linux
• A process is a computer program under execution, so, Linux is
running many processes at any given time.
• We can monitor them on the terminal using the ps command or on
the system monitor UI.
• For instance, let’s see an example of using the ps command to view
all the processes running on the machine:
ps –ef
• Linux processes are isolated and do not interrupt each other’s
execution.
• With a PID, we can identify any process in Linux.
Process in Linux
• Type the ps aux to see all running process in Linux.
• ps command is short for ‘Process Status’ PID
• PID - process ID
• TTY - terminal type
• TIME - total time the process has been running
• CMD - name of the command that launches the process
• To get more information using ps command use: ps -u
✓ CPU represents the amount of computing power the process is taking.
✓ MEM represents the amount of memory the process is taking up.
✓ STAT represents process state.
▪ While ps command only displays the processes that are currently
running, you can also use it to list all the processes. ps – A