OS Unit - 2
OS Unit - 2
Process Concept:
1 Stack
The process Stack contains the temporary data such as
method/function parameters, return address and local variables.
2 Heap
This is dynamically allocated memory to a process during its run time.
3 Text
This includes the current activity represented by the value of Program
Counter and the contents of the processor's registers.
4 Data
This section contains the global and static variables.
Process states:
Process control:
Process State
Process Privileges
Process ID
Pointers
Program Counters
CPU Registers
CPU Scheduling Information
Memory Management Information
Process ID: Unique Identification for each of the process in the operating
system.
Threads:
A thread is a single sequential flow of execution of tasks of a process so
it is also known as thread of execution or thread of control.
Apart from this, there can be more than one thread inside a process.
It takes far less time to create a new thread in an existing process than to
create a new process.
Threads can share the common data, they do not need to use Inter-
Process communication.
Context switching is faster when working with threads.
It takes less time to terminate a thread than a process.
Preemptive:
Once the processor starts its execution, it must finish it before executing
the other. It can’t be paused in the middle.
CPU utilization is less efficient compared to preemptive Scheduling.
Waiting and response time of the non-preemptive Scheduling method is
higher.
When any process enters the state of running, the state of that process
is never deleted from the scheduler until it finishes its job.
Non-preemptive Scheduling is rigid.
Examples: First Come First Serve, Shortest Job First, Priority Scheduling,
etc.
In non-preemptive scheduling process cannot be Scheduled
In this process, CPU is allocated to the process until it terminates or
switches to the waiting state.
Non-preemptive Scheduling has no such overhead of switching the
process from running into the ready state.
0 0 2 2 2 0
1 1 6 8 7 1
2 2 4 12 10 6
3 3 9 21 18 9
4 6 12 33 29 17
In SJF scheduling, the process with the lowest burst time, among the list of
available processes in the ready queue, is going to be scheduled next.
1 1 7 8 7 0
2 3 3 13 10 7
3 6 2 10 4 2
4 7 10 31 24 14
5 9 8 21 12 4
= 5.4
The formula of Round Robin Turn Around Time = Completion Time – Arrival
Time burst time.
The formula of Round Robin Waiting Time (W.T): Time Difference between the
turnaround and the burst time.
The formula of Round Robin Waiting Time = Turn Around Time – Burst Time
1 2 0 1 1 1 0
2 6 1 7 22 21 14
3 3 2 3 5 3 0
4 5 3 6 16 13 7
5 4 4 5 10 6 1
6 10 5 15 45 40 25
7 9 6 8 30 24 16
Process Control
File Management
Device Management
Information Maintenance
Communication
This system calls perform the task of process creation, process termination,
etc.
The Linux System calls under this are fork() , exit() , exec().
fork()
A new process is created by the fork() system call.
A new process may be created with fork() without a new
program being run-the new sub-process simply continues
to execute exactly the same program that the first (parent)
process was running.
It is one of the most widely used system calls under
process management.
exit()
The exit() system call is used by a program to terminate its
execution.
The operating system reclaims resources that were used
by the process after the exit() system call.
exec()
A new program will start executing after a call to exec()
Running a new program does not require that a new
process be created first: any process may call exec() at any
time. The currently running program is immediately
terminated, and the new program starts executing in the
context of the existing process.
File Management:
File management system calls handle file manipulation jobs like creating a
file, reading, and writing, etc. The Linux System calls under this are open(),
read(), write(), close().
open():
It is the system call to open a file.
Device Management:
Device management does the job of device manipulation like reading from
device buffers, writing into device buffers, etc. The Linux System calls under
this is ioctl().
ioctl():
ioctl() is referred to as Input and Output Control.
ioctl is a system call for device-specific input/output
operations and other operations which cannot be
expressed by regular system calls.
Information Maintenance:
It handles information and its transfer between the OS and the user program.
In addition, OS keeps the information about all its processes and system calls
are used to access this information. The System calls under this are getpid(),
alarm(), sleep().
getpid():
getpid stands for Get the Process ID.
The getpid() function shall return the process ID of the
calling process.
Communication:
pipe():
The pipe() system call is used to communicate between
different Linux processes.
It is mainly used for inter-process communication.
The pipe() system function is used to open file descriptors.
shmget():
shmget stands for shared memory segment.
It is mainly used for Shared memory communication.
This system call is used to access the shared memory and
access the messages in order to communicate with the
process.
mmap():
This function call is used to map or unmap files or devices
into memory.
The mmap() system call is responsible for mapping the
content of the file to the virtual memory space of the
Fork:
In an operating system, a fork is
a Unix or Linux system call to create a
new process from an existing running process. The
new process is a child process of the calling parent
process.
In computer programming, a fork is
when developers take the source code for an existing
project and use it to create new software based on the
original code.
The join instruction is the that instruction in the process execution that
provides the medium to recombine two concurrent computations into
a single one. The join instruction has one parameter integer count that
specifies the number of computations which are to be joined. It
decrements the integer by one. If the value of the integer after
decrement is non-zero then the process terminates otherwise the
process continues execution with the next statement.
exec family:
Wait:
pg. 22 ASST: PROF BANSARI SHARMA
In computer operating systems, a process (or task) may wait on another
process to complete its execution.
The parent process may then issue a wait system call, which suspends
the execution of the parent process while the child executes.
A call to wait() blocks the calling process until one of its child processes
exits or a signal is received. After child process terminates,
parent continues its execution after wait system call instruction.
It calls exit();
It returns (an int) from main
It receives a signal (from the OS or another process) whose default
action is to terminate.