CS_350_OS_PL_Presentation(1) Group 5
Download
Report
Transcript CS_350_OS_PL_Presentation(1) Group 5
CS 350
Operating Systems
&
Programming Languages
Group: Victor Yevtukh, Kyle Tassey, Ankit Tamakuala,
Matt Wetzel, David Yeager, Michael Wang, Yuan Xu
Operating Systems &
Programming Languages
Memory Management
Most of todays Programming langauges use
• Automatic memory management
• Manual memory management
BASIC, Erlang,
Haskell, JavaTM, JavaScriptTM, Lisp Perl,
Python, Scheme, Smalltalk, etc. [1]
[1] http://www.memorymanagement.org/articles/begin.html
Prolog,
• Manual Memory Management
Manual memory management is where the
programmer has direct control over when
memory may be recycled.
Advantages
• Easier for programmer to
understand/program
• Performance gains
Disadvantages
• Overload on the programmer (More repetative code
used for bookeeping of memory)
• More bugs
http://www.memorymanagement.org/articles/begin.html
Automic Memory Management
Automatic memory management is a service, either as a
part of the language or as an extension, that
automatically recycles memory that a program would not
otherwise use again
Advantages
• Memory management is typically faster
• More efficient
• The programmer is free from the problem
Disadvantages
• Memory may be retained because it is reachable,
but won't be used again;
• Automatic memory managers (currently) have limited
availability
Some Problems
• Dangling pointers
o
This is usually confined to manual memory management
o
Some programs continually allocate memory without ever giving it up and
eventually run out of memory.
• Memory Leak
• Poor locality of reference
o
Another problem with the layout of allocated blocks comes from the
way that modern hardware and operating system memory managers
handle memory: successive memory accesses are faster if they are
to nearby memory locations. If the memory manager places far apart
the blocks a program will use together, then this will cause
performance problems.
Example of a Flat memory Model Problem
•// "Give me 3 bytes of memory."
void* pMy3BytesMemory = malloc( 3 );
•// "Here are your 3 bytes of memory."
free( pMy3BytesMemory )
•Possible Errors/Problems
•-Memory Leaks
•-Buffer Overuns
•-Program Crashes
Multiprocessing
• All programming languages make use of multiprocessing
• Allows multiple programs to run simultaneously
• Without it, programs would have to run one at a time
Multiprocessing
• Scheduling Priorities
o high priority = most processor time
o low priority = least processor time
o maximum efficiency
o least downtime
Multiprocessing
• Avoid unproductive processing
o wastes resources
o busy waiting, timing loops, etc
o halt execution of a process not doing work
o most programming languages make use of monitors or
semaphores to accomplish this
signal when a process can run again
Multiprocessing
• Cache
o Many processes need resources from main memory
o Limited space in cache
but you want maximum cache hits
o The competition for cache space means the OS must
help decide which processes receive cache space to
minimize cache misses
Application Programming Interface
• The Operating System provides an API to programmers
so that they can write applications consistent with the
operating environment[1]
• The API acts as building blocks that the programmers
assemble into applications
• Windows, Linux, and Mac all have different APIs
[1]http://www.washington.edu/accessit/articles?15
Libraries
• A library is a collection of resources used in the
development of software
• Some libraries are system-specific (Standard Template
Libraries). A few system-specific libraries:
o <Windows.h> is specific to Windows
o <sys/types.h> is specific to Linux
o <sys/time.h> is specific to Linux
System Calls
• Applications make system calls to request information
from the operating system
• System calls made by Programming Languages include
read, write, open, close, etc.
• strace is a Linux command that can be used to show the
system calls of a program
strace for Hello World Program
strace
cont.
I/O
•
•
•
•
Handled by Operating System
Keyboard and other input devices
System Call to Operating System
Allows Portability of code
DIFFERENT OPERATING SYSTEMS
Three major Operating Systems
• Macantosh
• Windows
• Linux
Differences
-Most programming languages now are very friendly and can
run on different operating systems.
-operating system are designed differently so the
programming language needs to know which operating
system is running because for example, default windows
threads are different from the posix threads.
Differences
- Almost all the drivers for USB, Printing, FUSE and Graphics
for Linux are in the user space where as in Windows they
operate in the kernel space. And as Andy Tanenbaum put it, it
is better if more and more drivers run in the user space than
the kernel space as this makes the OS more reliable and
secure
- Linux kernel has inbuilt support for the most variety of file
systems.
-Both Linux and Windows kernels are developed using C and
assembly language but apart from that Windows also has a
significant percentage of C++ code.
continued..
- Linux kernel boots on diverse hardware architecture (around
22) including some game stations such as Sony Playstation.
Where as Windows support only a measly 3 architectures.
- Not surprisingly, the kernel size ofLinux is just over half of that
of Windows.
Programming Languages
• A programming language is an artificial language
designed to express computations that can be
performed by a machine, particularly a computer.
First Programming Languages
• The earliest programming languages predate the
invention of the computer, and were used to direct
the behavior of machines such as Jacquard looms
and player pianos
Syntax and Semantics
• A Programming Language has two components
• Syntax - he set of rules that define the combinations
of symbols that are considered to be correctly
structured programs in that language.
• Semantics - the meaning of language
Design
• Languages are either designed from scratch or a
combination of existing languages to meet new
needs in programming
• There is currently no universal language that serves
all purposes because of the diversity of contexts
languages are used in.
• Languages can differ by speed, size, simplicity,
reuse, and personal tastes of programmers
Implementation
• The implementation of a programming language
provides a way to execute that program on one or
more configurations of hardware and software.
• Two approaches to programming language
implementation
• Compilation: C/C++, Basic, Haskell, Ada
• Interpretation: Perl, Python, MATLAB, Ruby, Pascal,
and Java
Portability
Yuan Xu
• What is Portability?
• Run a program on different machines
• Works like:
Recompiling
Making small changes to the source code.
C Portability
• Core C
Extremely portable
• GNU C compiler,
• Standard I/O library
Mathematics routines
Internationalization
Java Portability
• “write once, run everywhere”.
Avoiding System Dependencies
• Location of key system files and directories
• Mail spools directory
/var/spool/mail
or
/var/mail.
• Local directory name.
Avoid absolute directory name!
• Avoid dependence on the size of a pointer or reference
being the same size as a particular integral type.
assert(int.sizeof == (int*).sizeof);
• Minimum integral and floating type sizes
32 to 64 Bit Portability
• Int bits
32 bits ==> 64 bits
• Pointers & object references
4 bytes ==> 8bytes
• Use size_t
Thank you ALL!