104-Set2-Processes.Pdf

104-Set2-Processes.Pdf

05/01/2017 Today Comp 104: Operating Systems Concepts • OS evolution Processes • Introduction to processes • OS structure Management Scheduling & Resource Allocation 1 2 Evolution of OS Multiprogramming • Largely driven by desire to do something useful when a • Load several programs into memory program cannot continue (maximise throughput ) simultaneously, all sharing single CPU • Early systems: –‘Job’ loaded from punched cards or tape, output to printer – Job may include loading compiler, assembler, linker, data etc. • When running program cannot continue – CPU idle for much of the time (e.g. waiting for I/O), switch to another • Batch systems: – Job passed to human operator – Operator groups jobs into batches with similar characteristics, e.g. all programs using same compiler • Hence, I/O and computation overlap – More efficient use of resources 3 4 1 05/01/2017 Multi-Access (Time-Sharing) Question • The following two statements describe the performance of two programs • An extension of multiprogramming (where the computation and input/output could be interleaved): – A performs a total of 20 seconds of computation and 15 seconds of input/output. – B performs a total of 30 seconds of computation and 10 seconds of I/O • CPU is switched rapidly between • Which of the following are true? processes to give illusion of uninterrupted I. It will take up to 50 seconds to run A and B sequentially II. It will take up to 75 seconds to run A and B sequentially execution in parallel (multitasking) III. Using multiprogramming, the shortest time to execute both is 50 seconds – users can interact with programs IV. Using multiprogramming, the shortest time to execute both is 40 seconds – users see their own ‘virtual machine’ a) I and III b) l and lV Answer: c – resources (printers, disks etc.) are shared, but c) ll and lll •If run sequentially, A needs to finish before B d) ll and lV can begin, therefore II is true. this is largely transparent •With multiprogramming, I/O for one process can e) None of the above take pave whilst the computation takes place for another. Therefore III is true 5 6 Operating System – An Abstract Implications View • Need to decide which programs to load from User Command Interface disk into memory (job scheduling) • Need to decide which program to execute next (CPU scheduling) Processor Manager • Consider disk space as extension of main memory (virtual memory) Memory Manager • Memory allocation Device Manager • Disk/file allocation • Protection/security File Manager 7 8 2 05/01/2017 Processes Process Characteristics • A program is a representation of an • Process characteristics: algorithm in some programming language; – Requires space in memory where it resides during i.e. it is static execution – During its execution it may require other resources • A process refers to the activity performed such as data files or I/O by a computer when executing a program; i.e. it is dynamic – It passes through several states from its initial creation to its completion within the computer system (more details on these states to come in later • A process is created when a program or lectures) command is executed 9 10 Processes Processes • A process needs resources, such as CPU time, • The Processor Manager is responsible for memory, files and I/O devices, to accomplish its task. overseeing the following activities in relation to process management: • These resources are allocated either when the – Creation and deletion of both system and user program is created, or when it is executing. processes • Operating-system processes execute system – Scheduling processes code and user-processes execute user code – Provision of mechanisms for synchronisation – All these processes could potentially execute and communication of processes concurrently – Deadlock handling for processes 11 12 3 05/01/2017 O.S. Structure Command Interpreter • Often consists of: • Accepts and runs commands specified by user – A central nucleus or kernel – Hence provides user’s view of OS • resides permanently in memory • May be graphical, e.g. Windows • performs low-level, frequently needed activity • May be textual, e.g. UNIX shell – A set of processes – bash, ksh, csh • may be system level or user level – Some commands built into shell, others loaded from – processes interact with kernel via system separate executable files calls – Shell also has sophisticated control structures such • e.g. create process, run program, open file as loops, if-statements and procedures – kernel and system level processes may operate in privileged mode 13 14 Process States State Changes • Running – on a uniprocessor machine, only one process can terminated be executing at any time new admitted – may be interrupted at end of time-slice if no I/O interrupt exit requests or system calls performed ready running • Ready dispatch – refers to a process that is able to run, but does not I/O or event I/O or event wait currently have the CPU completion • Waiting(Blocked) blocked – refers to a process that is unable to continue, even if granted the CPU 15 16 4 05/01/2017 Question Process Descriptors • A running process makes a system call to read data from a file. Which process state should it enter next? • For each process, the OS kernel maintainers a descriptor or Process Control Block (PCB) a) New • PCB contains info like b) Ready c) Running – unique process ID d) Blocked – user ID of process owner e) Terminated – process state – position in memory – accounting stats. (time used etc.) Answer: d Blocked; it may take some time before the file system can read the – resources allocated (open files, devices, etc.) file (e.g. on a networked file store), so the process is blocked until – register values (process counter, etc) the data is available. 17 18 Context Switch PCBs and Queuing • When a process is interrupted • The PCB of each process is updated as the – all current state information (including program process progresses from the start to the end of counter and other registers) is saved into PCB its execution – PCB is put into a queue • may have several, e.g. for different devices – the kernel may do some of its own work • Queues use PCBs to track the processes’ • e.g. handling a system call progress through the system. The PCBs are – the PCB of a process from the ready queue is linked to form queues: selected, and its context restored – ‘Ready queue’ linking the PCBs for every ‘ready’ • Whole context switch is an expensive process overhead – ‘New queue’ linking the PCBs for processes just entering the system – hardware support may help • e.g. multiple register sets 19 20 5 05/01/2017 PCBs and Queuing Queuing terminated new • Processes that are ‘blocked’ are linked together admitted by ‘reason for waiting’ interrupt exit ready running – PCBs for these processes are linked into several I/O or event dispatch queues completion • e.g. those waiting for I/O on a specific disk drive are linked together, those waiting for a printer are linked in a different blocked queue I/O request Disk I/O queue • All queues need to be effectively managed in an Printer I/O queue order that is determined by the process scheduling policies and algorithms Other I/O queue 21 22 Inter-Process Communication Signals • A process can usually be terminated by typing • Inter-Process Communication (IPC) CTRL-C mechanisms allow processes to talk to each – Actually sends a signal to process other – Process responds by aborting • IPC useful when processes working together • Signals can be sent from one process to another (cooperating processes) – signal() system call • Signals can be sent from the command line – synchronisation and/or passing data using kill command • For example in UNIX: – Format: kill -<signal> <pid> – signals – e.g. kill -9 12345 sends signal 9 (kill signal) to process 12345 – pipes – sockets 23 24 6 05/01/2017 Responding to Signals Pipes • A receiving process can respond • The UNIX command ‘wc –l file’ counts the number to a signal in three ways: Example kill signals of lines in file – Perform default action (e.g. abort) 1 HUP (hang up) • If we just type ‘wc –l’ we don’t get an error – Ignore the signal 2 INT (interrupt) 3 QUIT (quit) • Instead, data is read from standard – ‘Catch’ the signal; i.e. execute a 6 ABRT (abort) Common wc flags 9 KILL (non-catchable, non- input (keyboard by default) designated procedure ignorable kill) -l number of lines 14 ALRM (alarm clock) – Similarly for output files and standard -w number of words 15 TERM (software output (screen) -c number of characters • The ‘kill’ signal (signal 9) cannot termination signal) By default, all three be caught or ignored • The pipe symbol ‘|’ attaches the stats are displayed. – Guaranteed way to stop process standard output of one program to Flags state what stats appearL the standard input of another, e.g. 25 who | wc -l 26 Client-Server Examples • The following are examples of common servers: – Web server: accessed by client’s web browser – Mail server: retrieving and sending emails to clients – File server: holding documents to be accessed by clients – Database server: providing database services to clients, e.g. customer database, stock databaseL – etc 27 7.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us