Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Introduction Process

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 43

Process

Introduction
• A process is compiled source code that is currently
running on the system.
• In the UNIX operating system, Processes can be defined as
independent streams of computation which compete over the
machine's resources.
• A PROCESS is a program that is loaded into memory and
ready to run.
• Each process is identified by a unique integer known as
a process identifier (PID).
• Every process has a parent process with PPID.
• The child process is often started by the parent process.
• PID is unique.
Cont..
• When a process is created, the kernel assigns it a unique
identification number called a PROCESS ID or PID
• To keep track of all the processes in the system, the
kernel maintains a PROCESS TABLE, indexed by PID,
containing one entry for each process.
• Along with the PID, each entry in the table contains the
information necessary to describe and manage the
process.
• A small Unix system can easily have over 100 processes
running at the same time.
Cont..
• Most processes are started automatically to perform tasks in
the background.
• On a large system, there can be hundreds or even thousands
of processes all needing to share the system’s resources:
processors, memory, I/O devices, network connections, and
so on.
• In order to manage such a complex workload, the kernel
provides a sophisticated scheduling service, referred to as
the SCHEDULER.
• At all times, the scheduler maintains a list of all the
processes waiting to execute.
• The scheduler chooses one process at a time, and gives it a
chance to run for a short interval called a TIME SLICE.
Process Control Block (PCB)
• As the operating system supports multi-programming, it
needs to keep track of all the processes.
• PCB is used to track the process’s execution status.
• When the process makes a transition from one state to
another, the operating system must update information in
the process’s PCB.
• Some of the attributes of a process stored in PCB are:
• Process Id: Every process will be given an id called
Process Id to uniquely identify that process from the
other processes.
• Process state: Each and every process has some states
associated with it at a particular instant of time. This is
denoted by process state. It can be ready, waiting,
running, etc.
• CPU scheduling information: Each process is executed
by using some process scheduling algorithms like FCSF,
Round-Robin, SJF, etc.
• I/O information: Each process needs some I/O devices
for their execution. So, the information about device
allocated and device need is crucial.
• Program counter – indicates that the address of the next
instruction to be executed.
• Memory management information – represents the
memory being used by a particular process.
Process States
• During execution, a process changes from one state to another
depending on its environment/circumstances.
• In Linux, a process has the following possible states:
• New- the process is being created.
• Running – the process is actually running (it is the current
process in the system)
• Waiting – in this state, a process is waiting for an event to
occur or for a system resource.
• Additionally, the kernel also differentiates between two types
of waiting processes;
• interruptible waiting processes – can be interrupted by signals
and uninterruptible waiting processes – are waiting directly on
hardware conditions and cannot be interrupted by any
event/signal.
• Ready – the process is waiting to be assigned to the
processor.
• Terminated– the process has finished execution.
CPU Scheduling
• CPU Scheduling is a process of determining which
process will own CPU for execution while another
process is on hold.
• The main task of CPU scheduling is to make sure that
whenever the CPU remains idle, the OS at least select
one of the processes available in the ready queue for
execution.
• The selection process will be carried out by the CPU
scheduler.
• It selects one of the processes in memory that are ready
for execution.
Important CPU scheduling
Terminologies
• Burst Time/Execution Time: It is a time required by the
process to complete execution. It is also called running
time.
• Arrival Time: when a process enters in a ready state
• Finish Time: when process complete and exit from a
system
• Multiprogramming: A number of programs which can
be present in memory at the same time.
• Jobs: It is a type of program without any kind of user
interaction.
CPU Scheduling Criteria
• A CPU scheduling algorithm tries to maximize and
minimize the following:
First Come First Serve
• Characteristics of FCFS method:
• Jobs are always executed on a first-come, first-serve
basis
• It is easy to implement and use.
• However, this method is poor in performance, and
the general wait time is quite high.
• Suppose the processes arrive in the order: P1, P2,P3.
• The Ghant chart for the schedule is:

• Waiting time for P1=0,;P2= 24,P3=27


• Average waiting time: (0+24+27)/3
Round-Robin (RR)
• Each process gets a small unit of CPU time (time quantum),
usually 10-100 milliseconds. After this time has elapsed, the
process is preempted and added to the end of the ready queue.
• Performance;
✦ q large ⇒ FIFO
✦ q small ⇒ q must be large with respect to context switch,
otherwise overhead is too high.

• Characteristics of Round-Robin Scheduling


• Round robin is a hybrid model which is clock-driven
• Time slice should be minimum, which is assigned for a specific
task to be processed. However, it may vary for different
processes.
• It is a real time system which responds to the event within a
Example of RR

• The Gantt chart is:


Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible!
• Throughput – # of processes that complete their
execution per time unit!
• Turnaround time – amount of time to execute a
particular process (finishing time – arrival time)!
• Waiting time – amount of time a process has been waiting
in the ready queue after arrival!
• Response time – amount of time it takes from when a
request was submitted until the first response is
produced, not output (for time-sharing environment)!
Class Exercise
• Each team works on finding an average turnaround
time for a quantum time at 1, 2, 3, 4, 5, 6, 7.
Turnaround time – amount of time to execute a
particular process (finishing time – arrival time).
Process Creation and Termination
• How are processes created?
• Every process is created by another process.
• The kernel, which the core of OS, provides essential services to
process such as;
• Memory management (virtual memory management, including
paging)
• Process management (process creation, termination,
scheduling)
• Interprocess communication (local, network)
• Input/output with physical devices)
• File management
• Security and access control
• Network access (such as TCP/IP)
Cont..
• When a process needs the kernel to perform a service, it
sends the request by using a SYSTEM CALL.
• For example, a process would use a system call to
initiate an I/O operation.
• Specifically, the system calls used to create and use
processes are fork, exec, wait, and exit.
• The fork system call creates a copy of the current
process.
• The original process is referred to as PARENT
PROCESS.
• The new process, which is an exact copy of the parent,
is called the CHILD PROCESS or the CHILD.
Cont..
• The wait system call forces a process to pause until
another process has finished executing.
• The exec system call changes the program that a process is
running.
• Finally, the exit system call terminates the process.
• Unix/Linux systems generally have 200-300 different
system calls.
• The most commonly used system calls are the ones used
for process control (fork, wait, exec, exit and kill), and fi
le I/O (open, read, write and close)
Commonly used system calls
• The first thing the shell does is use the fork system call to
create a brand new process.
• The original process becomes the parent, and the new
process is the child.
• As soon as the forking is done, two things happen.
• First, the child uses the exec system call to change
itself from a process running the shell into a process running
the external program.
• Second, the parent uses the wait system call to pause itself
until the child is finished executing.
• Eventually, the external program finishes, at which time the
child process uses the exit system call to stop itself.
• Whenever a process dies, all the resources it was using —
memory, files, and so on — are deallocated, so they can be
used by other processes.
Orphans Processes
• What if a parent forks and then dies unexpectedly, leaving
the child all alone?
• The child keeps executing but it is now considered to be
an ORPHAN.
• An orphan can still do its job, but when it dies there is no
parent to wake up.
• On modern Unix systems, orphaned processes are
automatically adopted by process #1, the init process.
Distinguishing between Parent and
child
• Forking results in two identical processes: the original (the parent)
and the copy (the child), but one process has to wait and the other
has to run a program.
• If the parent and child are identical, how does the parent know it’s
the parent, and how does the child know it’s the child?
• When the fork system call has finished its work, it passes a
numeric value, called a RETURN VALUE, to both the parent and
the child process.
• The return value for the child is set to 0 (zero).
• The return value for the parent is set to the process ID of the newly
created child.
The very first process : init()
• If processes are created by forking, every child process must
have a parent.
• But then, that parent must have a parent of its own, and so on.
• Every Unix system has a process that at least indirectly
is the parent of all the other processes in the system.
• Init process is parent processes for all other process.
• Init process is started by a kernel.
• It’s process id is one(1).
Terminate Process - kill
• The kill program has two uses: to terminate a process and
to send a signal to a process.
• Programs run until they finish on their own or until you
tell them to quit.
• You can usually stop a program prematurely by pressing
CTR + C to send the INTR signal.
• For instance, a program will freeze and stop responding to
the keyboard. In such cases, pressing ^C will not work.
• In such cases, Processes can be terminated by using the
kill program.
• The syntax to use is: Kill [-9] pid | jobid
Sending a signal to a process
• Kill command is a powerful program that can send any signal
to any process.
• The more general form of the syntax is:
• kill [-signal] pid...|jobid... where signal is the type of signal
you want to send, and pid or jobid identifies a process.
• Interprocess communication or IPC is used for exchanging data
between two processes.
• It uses pipes as a means of sending data from one process to
another.

• The purpose of kill program is to support a different type of


IPC specifically, the sending of a very simple message called a
SIGNAL.
Background and Foreground Process.
• UNIX allows processes to run in the foreground or in the
background.
• Processes invoked from a shell command line are foreground
processes.
• Process that have been explicitly placed into the background by
appending an ampersand '&' to the command line are
background process.
• There can be only one process group in the foreground at any
time.
• There is no limit to the number of background processes.
• Foreground processes can read from and write to the
terminal.
• Background and foreground processes use the terminal as
their control terminal, but background processes do not
receive all signals from that terminal.
• A Ctrl-C, for example, will not cause a SIGINT to be sent
to background processes.
• A SIGHUP will be sent to all processes that use that
terminal as their control terminal, including background
processes.
• if a terminal connection is broken, all processes can be
notified of it and killed by default.
Job Control
• Jobs - List the active jobs from the current shell.
• Active jobs are current background and stopped processes
started from current shell (not processes started from other
running shells from the same user).
• The listed number for each job can be used with the fg and
bg commands.
• Fg - Move a background or stopped process to the
foreground.
• Use the job number from the jobs command to identify the
target job.
• Bg - Restart a stopped process as background process.
• Use the job number from the jobs command to identify
the target job.
• Nohup - Prevent termination of the process when the
user logs out.
• Syntax : nohup command [ command options and
arguments ] &
• Normally, background processes are terminated when
the user logs out.
• nohup prevents this from happening.
Process Priority
• Every running process in Unix has a priority assigned to
it.
• Unix Kernel schedules the process and allocates CPU
time accordingly for each of them.
• But, when one of your process requires higher priority to
get more CPU time, you can use nice and Renice
command.
• We can display the information about active processes
using ps command.
• By default, ps command only shows current user’s
processes.
Nice and Renice Command

• You can change the process priority using nice and Renice
utility.
• Nice command will launch a process with an user defined
scheduling priority.
• Renice command will modify the scheduling priority of a
running process.
• The process scheduling priority range is from -20 to 19. We
call this as nice value.
• A nice value of -20 represents highest priority, and a nice
value of 19 represent least priority for a process.
Cont…
• This guidelines are called niceness or nice value.
• The easiest way to get a quick picture of what the current
niceness priority on a process is to open up the top
processes with:
• Top command or Htop
ps command
• The current priority of a process can be displayed using ps
command.
• The “NI” column in the ps command output indicates the current
nice value (i.e priority) of a process.
• Example: test program called test.pl which will be used to
demonstrate nice and renice command.
• $ perl test.pl
• $ ps -fl -C "perl test.pl"
• F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY
TIME CMD
• 0 R bala 6884 6424 99 80 0 - 1556 - 13:45 pts/3 00:05:54 perl
test.pl.
• Now, let us stop the running program cmus with
command: $ kill -9 13829
Process Priority
Contd..
Contd..
Contd..
Contd..
End of the Lesson
Next: File System

You might also like