1 / 28

Lecture 9: SHELL PROGRAMMING (continued) Creating shell scripts!

Lecture 9: SHELL PROGRAMMING (continued) Creating shell scripts!. NAME chex-change a file to be executable SYNOPSIS chex filename

teenie
Download Presentation

Lecture 9: SHELL PROGRAMMING (continued) Creating shell scripts!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 9:SHELL PROGRAMMING (continued)Creating shell scripts!

  2. NAMEchex-change a file to be executable SYNOPSISchex filename DESCRIPTIONThis is the outline for chexSelect shApply chmod u+x to file named as argument ($1)Inform user that file is executableUse ls-l to show the file modes Making a File Executable

  3. NAMEmywc-labeled word count SYNOPSISmywc filename DESCRIPTIONThis is the outline for mywcSelect shRun wc on $1 and capture output with setPrint the filename ($4)Print the number of lines ($1)Print the number of words ($2)Print the number of characters ($3) Labeling the output from wc: mywc

  4. NAMEdel- delete a file interactively SYNOPSISdel filename DESCRIPTIONThis is the outline for delSelect shGet the filename from the command line ($1)If there is no file with that nameprint an error message OtherwiseAsk if the user wants to delete the fileRead the user's choice (y/n)If the choice is yes (y)remove the file and print a messageotherwise print a message Removing files safely: del

  5. NAMEtickle- a daily reminder service SYNOPSIStickle DESCRIPTIONThis is the outline for tickleSelect shUse set to capture the output from datePrint a messageCheck day ($1) and print an appropriate message A daily reminder system: tickle

  6. NAMEmyspell- an improved spelling-checker SYNOPSISmyspell file DESCRIPTIONHere is the outline for myspell:Select shRun shell on the file; for each misspellingdoRun grep to find lines with misspellingsPrint the misspelled wordPrint the line(s) containing misspellingsdone An improved spell program

  7. Memory Management

  8. Memory Allocation • Information in memory are used in many different ways. Some classifications are: • Programming Language • Instructions: specify the operations to be performed • Variables: information that change during the program execution • Constants: information used as operands, but never change • Changeable • Read-only: program code , constants • Read-Write: variables

  9. Memory Allocation (ctd) • Initialised • Yes: for code, constants, and some variables • No: Most variables • Static or Dynamic location • Static: data are stored at a fixed address • Dynamic: the location can be changed if the memory is rearranged (garbage collection, relocation) • Binding time (when the memory is allocated to objects) • Static: location is determined before the program execution (compiler, linker, loader) • Dynamic: location is defined at runtime and it may change

  10. 0x000... Code Data Heap Stack 0x7fff... Memory Allocation (ctd) • What does a process in memory look like? • In Unix OS, it is divided into areas called segments • Code (text) segment, Data and Stack segments • Why a process has different segments? • Isolate read-only data from read-write data

  11. Memory Management • Memory management is vital in computer systems: memory needs to be allocated efficiently to pack as many processes into memory as possible • The OS process that manages memory is called memory manager • The memory manager process has the following roles: • Keep track of which parts of memory is in use which parts are not • Allocate memory to processes when they need it and de-allocates it when they are done • Manage swapping between main memory and disk when the main memory can not hold all the processes

  12. Multiprogramming Systems • Multiprogramming • Providing interactive service to several people simultaneously • Ability to have more than one process in memory at once in order to achieve reasonable performance • Improving performance by attempting to keep the processor(s) busy all the time • suspend processes when they are executing I/O operations • run processes which are not executing I/O operations

  13. I/O Performance

  14. Memory Systems • During the process execution the memory unit • sees only a stream of memory addresses • does not know how addresses are generated • The memory unit is interested only in the sequence of memory addresses

  15. Binding and Relocation • Compile Time • Absolute code can be generated • Need to recompile if the starting location has changed • Example: MS-DOS “.COM” programs • Load Time • Re-locatable code is generated at compile time • The binding is done at load time • No need to recompile if the starting location has changed • Run-Time • The binding is done at the execution time • The process can be moved from one memory segment to another • Special hardware must be provided to implement this scheme (MMU)

  16. OS in ROM OS in ROM User Program No swapping & No paging User Program User Program OS in RAM OS in RAM MM Systems • MM systems can be divided into 2 classes: • no swapping and no paging – Mono-programming • swapping and paging – Multiprogramming

  17. Memory Organisation • How should memory be organised in order to have more than one process in it ? • First solution: divide the memory into n fixed partitions not necessarily equal • Second solution: divide the memory into variable partitions (dynamic partitioning) • Third solution: virtual memory technique

  18. Multiple input queues Single input queue Partition 4 Partition 4 Partition 3 Partition 3 Partition 2 Partition 2 Partition 1 Partition 1 OS OS Fixed Partitions

  19. Fixed Partitions (ctd) • Advantages • simple implementation and effective on batch systems • Disadvantages • Create internal fragmentation problem • A multiple input queues strategy can lead to dramatic loss of memory performance (when large partitions are empty and the queue for small jobs is full) • Not suitable for a large number of processes • Not suitable for time-sharing model because of the dynamic behaviour of the system • The size of processes is not taken into account

  20. Variable Partitions • Features • Used when the number and size of the processes in memory vary dynamically • The size of processes is taken into account • Number, location and size of the partitions vary dynamically depending on the processes running in the system • Creates external fragmentationproblem • The external fragmentation can be solved by compaction

  21. Variable Partitions 128K 128K 128K 128K O/S O/S O/S O/S Process 1 320K Process 1 320K Process 1 320K Process 2 224K Process 2 224K Process space Process space Process 3 896K 576K 288K 352K 64K 128K 128K 128K 128K O/S O/S O/S O/S Process 2 Process 1 320K Process 1 320K 320K 224K 96K Process 4 128K Process 4 128K 224K 96K 96K Process 4 128K Process 3 288K Process 3 Process 3 288K 288K 96K 64K 288K Process 3 64K 64K 64K

  22. Paging Technique • Overlays • When a program is too big to fit in the available memory, the programmer has to split it into pieces • The swapping is done by the OS • Paging • The physical memory is partitioned into small equal fixed-size chunks (called frames) • The logical memory is also divided into small and equal fixed-size chunks (called pages)

  23. Paging Technique (ctd) • Features • Internal fragmentation: only a fraction of the last page of a process • No external fragmentation • In order to load the pages of a process into non contiguous frames the OS needs page table for each process • Logical address consists of a page number and an offset within the page • Translation logical-to-physical address is done by the processor hardware

  24. Logical Address Physical Memory CPU P d F d Physical Address P Page table Paging Hardware

  25. Logical Address CPU P d Physical Memory TLB hit F d Physical Address P TLB miss Page table Paging Hardware

  26. Analysis • Definition • Hit ratio: percentage of times that a page number is found in the associative registers • Performance • Effective Access Time: • Hit ratio x TLB access time + Miss ratio x Memory access time

  27. Segmentation Technique • Segmentation • The logical memory is divided into a number of segments of different length • Logical address consists of two parts: segment number and an offset • Features • With segmentation a process may occupy more than one partition • Internal fragmentation: solved • External fragmentation: Not solved

  28. trap: addressing error No Physical Memory Yes < CPU S d + S Segment table limit Base

More Related