Computer Hardware and System Software Concepts Introduction to concepts of Operating System (Process & File Management)

Welcome to this course on Computer Hardware and System Software Concepts

1

RoadMap Introduction to Process Management Introduction to File Management

Copyright © 2004, Infosys Technologies Ltd

2

ER/CORP/CRS/OS09/003 Version No: 2.0

•Day3 •Introduce Process Management •To introduce the following: •Process •Process state transition •Scheduling •Introduce File Management •Illustrate the concept of storage structure with respect to DOS and Unix file system ( elementary)

2

Operating System Process Management

The job of process management is to take care of issues like life-cycle of a process (creation, control and termination), scheduling, timing the process etc.

3

Process Management Functions: – To keep track of the status of each process – To suspend and choose some processes based on some criteria – To coordinate interprocess communication

Copyright © 2004, Infosys Technologies Ltd

4

ER/CORP/CRS/OS09/003 Version No: 2.0

We are going to focus on what are processes, what is the state of a process and how are processes scheduled in the next few slides.

4

Some concepts Processor – Hardware component that is capable of executing instructions

Process – An instance of a program in execution – Is an active entity whereas a program is a passive entity – Needs certain resources for execution in which a processor is one of them

Copyright © 2004, Infosys Technologies Ltd

5

ER/CORP/CRS/OS09/003 Version No: 2.0

The computer system today allows multiple programs to be loaded into memory and to be executed concurrently but at one point of time only one program is in execution or rather at most one instruction is executed on behalf of the process. A program is a passive entity. For e.g. the contents of a file stored on a disk. A process is an active entity – it has a PC (program counter) which specifies the next instruction to execute. There may be two processes associated with the same program but they are considered to be two different execution processes. For e.g one user invoking many copies of the editor program.

5

Structure of a process Code Region : Contains the executable instructions of the process Data Region : Holds the data areas used by the process Stack Region : Holds the dynamic data such as local data in a procedure,arguments to a procedure/function etc. Program Counter (PC): The PC gives the address of the next instruction to be executed by the process.

Copyright © 2004, Infosys Technologies Ltd

6

ER/CORP/CRS/OS09/003 Version No: 2.0

We all know that the executable code is a sequence of binary stuff. This is a passive code and and has no life. However, the moment it becomes a process it has life in it. There are three logical components in it. •Code Region – It contains the executable instructions of the process i.e it contains the current activity as represented by the value of the program counter and the contents of the processor’s registers. •Data Region – Contains the data areas used by the process which is again divided into initialized and un-initialized part. For e.g all global variables are stored in data region •Stack Region – A process also includes process stack which contains temporary data such as subroutine parameters, return addresses and temporary variables.

6

States of a process New

: Created

Ready : Assign a process to a processor Run : Instruction execution Blocked : For an event to occur (Eg.I/O) Terminated : Finished execution

Copyright © 2004, Infosys Technologies Ltd

7

ER/CORP/CRS/OS09/003 Version No: 2.0

Here, the instructor must draw the state diagram in a piecemeal fashion slowly adding the complexity and inviting more questions. •New – Here the operating system recognizes the process but does not assign resources to it. •Ready – The process is ready/waiting to be assigned to a processor. •Run – When a process is selected by the CPU for execution, it moves to the run state. •Blocked – When a process is waiting for some event to occur, say for e.g I/O completion or reception of a signal then it is in the blocked state i.e. when a running process does not have immediate access to a resource it is said to be in the blocked state. •Terminated – This is the state reached when the process finishes execution.

7

State transitions of a process

Batch job enters system

INPUT interactive job enters system

scheduler wakeup

READY

BLOCKED

Remove

dispatch

RUN Interactive job leaves system

terminate

OUTPUT Copyright © 2004, Infosys Technologies Ltd

Batch job leaves system 8

ER/CORP/CRS/OS09/003 Version No: 2.0

The states are shown in boxes and the state transitions are indicated on the edges. When a job enters the system, it is in the INPUT stage. Thereafter, resources are assigned to it and it moves to the READY state. The moment the processor picks its up for execution, then it goes to the RUN state. If it finishes execution then it goes to the OUTPUT or FINISHED state. In the RUN state, if the process requires I/O or has to wait for some other resource, then it goes to the BLOCKED state. Once it has got the required resource or I/O is over, then it goes to the READY state again from the BLOCKED state and has to wait for the processor to pick it up to go to the RUN state and the same cycle follows. There can be more than one processes in the READY state where as there can be only one process in the RUN state.

8

Context switching The task of switching the CPU to another process by saving the state of the old process and loading the saved state of the new process is known as context switching Context switching – Keeps the CPU busy all the time – Occurs when any of the following situations is encountered • An I/O operation is initiated • An interrupt occurs • An I/O is completed • A process terminates

Copyright © 2004, Infosys Technologies Ltd

9

ER/CORP/CRS/OS09/003 Version No: 2.0

Context switching is a overhead as the system does not do any useful work while switching. Its speed varies from machine to machine – depends upon the memory speed, the no. of registers to be copied etc. Since at any point of time there could be more than one process waiting to be serviced by the CPU, these have to be put in hold at some place. A queue is a place where the IN and OUT of the process is controlled. There are different queues for different purposes. Example: •I/O Queue – If the process is waiting for an I/O operation to complete, then it goes to the I/O queue. •Job queue – A process entering the system for the first time goes into the Job queue.

9

Concurrent processes Concurrent processes execute in operating systems and can be of two types viz., – Independent – Co-operating

Independent process - are those processes which cannot affect or be affected by other processes executing in the system.

Copyright © 2004, Infosys Technologies Ltd

10

ER/CORP/CRS/OS09/003 Version No: 2.0

Independent process – are those processes which cannot affect or be affected by other processes executing in the system. They do not share any data with any other process. Co-operating process – are those processes which can affect or be affected by other processes executing in the system. They can share data with any other process.

10

Co-operating processes Benefits – Sharing of information – Computation speed-up – Modularity – Convenience

Communication – Message passing – Shared memory

Copyright © 2004, Infosys Technologies Ltd

11

ER/CORP/CRS/OS09/003 Version No: 2.0

•Information sharing - Several users may be wanting to use the same file. In such cases, it is ideal to provide an environment to allow concurrent access to such resources. •Computation speed-up – To speed-up a particular task, we can break it into several sub-tasks each of which would be executing in parallel with the others. NOTE: This would require multiple CPUs and I/O channels. •Modularity – The user might want to construct the system in a modular fashion by dividing the system’s functions into separate processes. •Convenience – A user too might have many tasks to do at the same time say for e.g. User X might be compiling, printing and editing at the same time. Communication: •Message Passing – In order to exchange messages, there must be at least two operations available with the processes such as send and receive. The two processes communicating with each other should agree with certain logical issues such as how to establish links, can the same link be associated with more than one process, is the link unidirectional or bi-directional etc. •Shared Memory – Processes also can communicate by sharing memory. In these cases, the computers are usually in close proximity.

11

Some concepts Uniprogramming Multiprogramming Multiprocessing Multitasking

Copyright © 2004, Infosys Technologies Ltd

12

ER/CORP/CRS/OS09/003 Version No: 2.0

•Uniprogramming – There is only one processor that processes only one job at a time. •Multiprogramming - There is only one processor but can be multiple processes running •Multiprocessing - There is only one processor but can be multiple processes running •Multitasking – •Systems execute many programs concurrently •Residence of many programs in the memory •One program runs at any point of time •Other programs potentially can run

12

Scheduling Policy to decide which ready process is to be picked up next. Criteria which lets a particular policy to be chosen are the following: – CPU Utilisation – Throughput – Turnaround time – Waiting time – Response time

Copyright © 2004, Infosys Technologies Ltd

13

ER/CORP/CRS/OS09/003 Version No: 2.0

How is it different from context switching? Context-switching + some more information = Scheduling. Context switching merely states that CPU makes a transition to another process. The question as which another process is decided by a policy and that is all about scheduling •CPU Utilisation - What percentage of CPU is being under utilization •Throughput - Indicates how many processes have been through per unit time •Turnaround time - Time span between submission of a job till it gets completed •Waiting time - Sum of all the individual times spent in the ready queue •Response time - Time from submission of the request until the first response is produced. Mainly useful in an interactive environment

13

Scheduling policy Scheduling policies are of two categories – Non-Preemptive scheduling – Preemptive scheduling

Copyright © 2004, Infosys Technologies Ltd

14

ER/CORP/CRS/OS09/003 Version No: 2.0

The CPU scheduling decisions usually takes place under the following conditions: 1. When a process switches from the RUN state to the BLOCKED state. 2. When a process switches from the RUN state to the READY state. 3. When a process switches from the BLOCKED state to the READY state. 4. When a process terminates The scheduling scheme is non-preemptive for case 1 and 4 else it is preemptive.

14

Non-preemptive scheduling CPU is allocated to a process till the job is over or incurs an I/O wait Example – FCFS ( First Come First Serve )

Disadvantage Monopoly of the process

Copyright © 2004, Infosys Technologies Ltd

15

ER/CORP/CRS/OS09/003 Version No: 2.0

In non-preemptive scheduling, the process cannot forcibly loose the processor. The CPU is allocated to a processor till it gets over or incurs an I/O wait. The main disadvantage is monopoly of a process as a single process can draw all the attention of the CPU maliciously or otherwise.

15

Example Find the average waiting time for FCFS for the following processes whose CPU time is given below: P1 – 6 ms P2 – 8 ms P3 – 7 ms P4 – 3 ms

Copyright © 2004, Infosys Technologies Ltd

16

ER/CORP/CRS/OS09/003 Version No: 2.0

Solution: Waiting time for P1 = 0ms Waiting time for P2 = 6ms Waiting time for P3 = 14ms Waiting time for P4 = 21ms Average waiting time = 41/4 = 10.25ms

16

Preemptive scheduling Fixed time slice is specified during which a process gets attention If the process gets terminated before the time slice then CPU makes a context switch Example – Round Robin – Shortest Job First(SJF)

Copyright © 2004, Infosys Technologies Ltd

17

ER/CORP/CRS/OS09/003 Version No: 2.0

Round Robin: It is similar to FCFS scheduling only pre-emption is added to switch between processes. In this scheme, a time quantum (say 1 ms) is defined. A ready queue is treated as a circular queue and the CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval upto 1 ms. To implement RR scheduling the ready queue is kept as a FIFO queue of processes. New processes are added to the tail of the queue. The CPU scheduler picks the first process from the ready queue, sets the timer to interrupt after 1 ms and dispatches the process. If the process has a CPU burst of time less than 1 ms, the process itself will release the CPU voluntarily and the scheduler will pick up the next process in the ready queue. If the CPU burst of the current process is more than the allocated time quantum, then the timer associated with the process will be off and will cause an interrupt to the OS. The context switch will be executed and the process will be put at the tail of the ready queue. The CPU scheduler will select the next process in the ready queue. SJF: The SJF algorithm may be either preemptive or non-preemptive. The choice arises when a new process arrives at the ready queue while the previous process is executing. The new process might have a shorter next CPU burst than what is left of the currently executing process. A preemptive SJF algorithm will preempt the currently executing process where as a non-preemptive SJF algorithm will allow the currently running process to finish the CPU burst. A preemptive SJF algorithm is also known as “shortest remaining time first” algorithm.

17

Operating System File Management

18

File Management Part of the Operating System that deals with effective information management Features: – Minimal I/O operations on files – Flexibility between logical and physical block size – Automatic allocation of file space – Flexible file naming facility such as links, aliases etc

Copyright © 2004, Infosys Technologies Ltd

19

ER/CORP/CRS/OS09/003 Version No: 2.0

19

File systems MSDOS - file system UNIX - file system

Copyright © 2004, Infosys Technologies Ltd

20

ER/CORP/CRS/OS09/003 Version No: 2.0

We will look at case study of the two file systems viz., MS-DOS file system and UNIX file system. The moment we turn the computer on, the computer loads a special program called the operating system into the computer’s memory which provides an environment for us to run other programs. The OS provides an interface between the application programs and the hardware. DOS (Disk Operating System) is the operating system for IBM PCs and PCcompatibles. There are 2 flavors of DOS viz., PC-DOS and MS-DOS. PC-DOS is mainly for IBM PCs where as MS-DOS is licensed by Microsoft for PC-compatibles. From the user perspective, there is no difference.

20

MS DOS-File system MS-DOS has a tree structure i.e. files are organized on each logical drive within a hierarchical directory structure. Root directory is the top directory which holds numerous files and subdirectories.

Copyright © 2004, Infosys Technologies Ltd

21

ER/CORP/CRS/OS09/003 Version No: 2.0

When one first formats a disk, DOS creates a single directory on the disk known as root directory. This directory is so named because all the directories which are created later grow from the root, just like the branches of a tree. Let us take the example of a cabinet as an analogy. We can simply put a number of files in the cabinet or we can create a number of drawers (compartments) in the cabinet. This would help to organize the files properly. The cabinet can be considered as the root directory and the drawers as directories – the purpose is essentially the same i.e it helps to organize information. DOS uses the backslash character (\) to represent directory or sub-directory. The root directory, also known as home directory is represented by backslash (\) alone. This is the default directory if no name is specified after the backslash. DOS selects one disk drive as the current drive or current directory unless specified otherwise. The current directory can also be changed with the CHDIR command.

21

MS DOS-File system Naming convention in DOS consists of – Logical drive – Path – Filename

Example:

C:\ER\CHSSC\CHAPTER.DOC

Copyright © 2004, Infosys Technologies Ltd

22

ER/CORP/CRS/OS09/003 Version No: 2.0

Drivename : C Pathname: 2 directories viz., ER & CHSSC Filename: CHAPTER.DOC

22

MS DOS – Data access Basic allocation units of each drive- CLUSTERS chkdsk is used to find the cluster size in a system Each drive has a file-allocation table (FAT) FAT is a roadmap that DOS follows to locate the clusters belonging to a particular file.

Copyright © 2004, Infosys Technologies Ltd

23

ER/CORP/CRS/OS09/003 Version No: 2.0

This topic deals with how files are organized in the hard disk and how a user can access them. The operating system allocates disk space on demand by user programs. A disk is divided into sectors and tracks. Each sector is usually 512 bytes. Normally, the space is allocated in units of fixed size known as clusters. A cluster is a multiple of sector size i.e. multiples of 512 bytes say 512, 1024, 2048 bytes etc. When a user creates a directory, DOS allocates a cluster to hold the directory entries. Each directory entry requires 32 bytes. If a disk uses 2048-byte clusters (assuming), a single cluster can hold 64 directory entries(2048/32). Now, if the directory contains more than 64 entries, DOS must allocate a second cluster. Thus, DOS stores files on disks in groups of sectors called clusters or allocation units. The file may fit in a single cluster or a group of clusters depending on the file’s size. DOS tries to store the clusters belonging to a particular file in consecutive disk locations as far as possible. However, in some cases, the clusters of another file may prevent DOS from using consecutive locations.

23

MS DOS – Data access The entry in the FAT corresponding to each cluster contains a value that indicates:

» which cluster is unused » which cluster is reserved » which cluster considered as a bad cluster » the number of next cluster in the file » the last cluster of the file

Copyright © 2004, Infosys Technologies Ltd

24

ER/CORP/CRS/OS09/003 Version No: 2.0

24

How to access the contents of a file?

mydoc

0000

0006

2

3

3

5456 bytes

txt

0000

0000

0007

4

5

6

Copyright © 2004, Infosys Technologies Ltd

25

FFFF

7

0000

8

CLUSTERS

FAT ENTRIES

ER/CORP/CRS/OS09/003 Version No: 2.0

The diagram in the slide above shows how to access the contents of a file. This shows the directory entry of a file mydoc.txt of 5456 bytes which begins with entry no. 3 which is the cluster no. of the first cluster of the file. Location 3 above stores the value 0006. Location 6 stores the value 0007. Location 7 stores the value FFFF which implies that it is the end of the file. Thus by accessing the FAT table, we can say that the contents of mydoc. txt file are there in cluster nos. 3, 6 and 7.

25

Volume structure in MS-DOS Boot-sector : Contains a bootstrap loader and disk characteristics FAT : Main file allocation table Additional FAT : used for recovery during the failure of main FAT Root directory : It is in a fixed position of fixed size File space : Rest of disk space which is available for files and sub-directories.

Copyright © 2004, Infosys Technologies Ltd

26

ER/CORP/CRS/OS09/003 Version No: 2.0

The boot sector contains details about the characteristics of a disk and a bootstrap loader. When the computer is switched on first, the boot sector is automatically read from the disk by the ROM start up program and executed. This causes an immediate jump to the bootstrap loader code, which in turn finds the operating system files, MS-DOS.SYS and IO.SYS in the root directory. These are loaded into the memory and executed which in turn makes the operating system operational.

26

File permissions in MS-DOS read-only : a file cannot be written or deleted hidden : such files ignored by many commands system : such files sre system files ( OS related files) archive : used for back-up

Copyright © 2004, Infosys Technologies Ltd

27

ER/CORP/CRS/OS09/003 Version No: 2.0

In DOS, the command attrib will show the permissions attached to a file. A file can have the following attributes viz., •Read-only •Hidden •System •Archive Security feature is very poor in DOS

27

UNIX File system UNIX has multiple file systems A file system – is a formatted partition of the disk – Is a group of files having relevant information

There is always one compulsory file system known as the root.

Copyright © 2004, Infosys Technologies Ltd

28

ER/CORP/CRS/OS09/003 Version No: 2.0

The origin of UNIX can be traced back to 1965, Bell Telephone Laboratories, General Electric Company and MIT took up a joint venture to develop an operating system that could serve a large community of users and also allow them to share data. A hard disk may comprise of a single file system or it can also be partitioned to house several file systems. The reverse is however not true. No file system can be split over two different disks. One file system called as root is compulsory; others can be created by the administrator and mounted at some point in the hierarchy before use.

28

Volume structure in UNIX Boot block : occupies the beginning of the root file system Super block : Has the state of the file-its size,where to find the free space on the file system,how many files it can store etc. Inode list : It follows the super block-Give the internal representation of the file Data Block : Contains data.( Size of the blocks can vary from 512 bytes to 4K)

Copyright © 2004, Infosys Technologies Ltd

29

ER/CORP/CRS/OS09/003 Version No: 2.0

The UNIX file system is somewhat different from the MS-DOS file system. The disk space allotted to a UNIX file system is made of blocks of usually 512 bytes. All the blocks belonging to a file are divided into four parts viz., •Boot Block - occupies the beginning of the root file system and contains a program called bootstrap loader. This program is executed when the host machine is booted. •Super Block - Has the state of the file-its size, where to find the free space on the file system, how many files it can store etc. •Inode Table – UNIX treats everything it knows and understands as files. The information related to these files is stored in a table known as Inode Table on the disk. For each file, there is an inode entry in the table. Each entry is approx 64 bytes and contains details such as •Owner of the file •Type of the file •File access permissions •File access time •Size of the file •Date and time of last access etc •Data Block – contains the actual file contents. An allocated block can belong to only one file in the file system.

29

Inode pointer structure DATA BLOCKS

INODE Direct 0 Direct 1 Direct 9 Single indirect

. . .

Double indirect Triple indirect Copyright © 2004, Infosys Technologies Ltd

30

ER/CORP/CRS/OS09/003 Version No: 2.0

Each inode entry in the inode table consists of 13 addresses each. These addresses specify where exactly the contents of the file are stored on the disk. These addresses are numbered 0 to 12. The first ten adddresses viz., 0 to 9 point to 1 KB blocks on disk and thus can handle a file size upto 10 KB. The 11th entry contains the address of a 1KB block. (This block does not contain the file contents) .This block contains 256 more slots or addresses each of which in turn can point to a 1 KB block on disk. The maximum size that can be addressed using the 10th entry is 256 KB. This is called Single Indirection. The 12th address in the inode table points to a block of 256 addresses each of which in turn again points to another set of 256 addresses. These addresses point to 1 KB data chunks. Thus the maximum file size accessible by this is 256 * 256 i.e. 64 MB. This is known as Double Indirection. Similarly, the maximum file size accessible by the 13th address in the inode table is 256*256*256 i.e. 16GB. This is known as Triple Indirection. Thus, together the maximum file size that UNIX can provide is 10 KB + 256 KB + 64 MB + 16 GB which is quite vast.

30

Types of users in UNIX OWNER : the owner of the file GROUP : all members in the group OTHERS : all other users in the environment Categories of file permissions – Read only – Write only – Execute only

Copyright © 2004, Infosys Technologies Ltd

31

ER/CORP/CRS/OS09/003 Version No: 2.0

There are 3 types of users in Unix viz., •Owner •Group •Others For each of the above categories, following permissions can be attached i.e. •Read only – denoted by r •Write only – denoted by w •Execute only – denoted by x Example: If all the users are given all the permissions then the file will show the permissions as rwxrwxrwx. The first three slots are for the owner, the next three for the group and the last three for others. If the owner decides to have read, write and execute permissions only for himself and only read permission to others then the file will have rwxr—r– permissions.

31

Operating System THE END

32

Computer Hardware and System Software Concepts

Infosys Technologies Ltd. RoadMap. Introduction to Process Management. Introduction to File Management. •Day3. •Introduce Process Management. •To introduce the following: •Process. •Process state transition. •Scheduling. •Introduce File Management. •Illustrate the concept of storage structure with respect to DOS and ...

174KB Sizes 0 Downloads 31 Views

Recommend Documents

The Architecture of Computer Hardware, Systems Software, and ...
Software, and Networking: An Information Technology Approach epub vk The ... networking as it relates to computer systems as well as all kinds of business systems, from entrepreneurial to small business, networked, ... applied in the field.

Software and hardware list.docx.docx - GitHub
Download links to the software. Hardware specifications. OS required. 1. 32-bit / 64-bit guest OS. Free. None. Windows/Mac. OS/Debian/RedHa t/CentOS/SUSE/U buntu. 2. R. 3.X.X/RStudio. Desktop V0.9X. Free. R http://www.r-project.org/. RStudio https://

PDF Embedded System Design: A Unified Hardware/Software ...
Online PDF Embedded System Design: A Unified Hardware/Software Introduction, Read PDF Embedded System Design: A Unified Hardware/Software Introduction, Full PDF Embedded System Design: A Unified Hardware/Software Introduction, All Ebook Embedded Syst