Lecture 1 RunTime Environments.

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

Threads, SMP, and Microkernels
Operating System Structures
Chap 2 System Structures.
SLC/Ver1.0/OS CONCEPTS/Oct'991INTRODUCTION What is an Operating System? Operating Structure -System Components -OS Services -System Calls & Programs -System.
Operating System Structure
Operating-System Structures
Cs238 Lecture 3 Operating System Structures Dr. Alan R. Davis.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: System Structures.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 14, 2005 Operating System.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Introduction to Operating Systems Chapter 1. cs431 -cotter2 Lecture Objectives Understand the relationship between computing hardware, operating system,
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 7 OS System Structure.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
C o n f i d e n t i a l 1 Course: BCA Semester: III Subject Code : BC 0042 Subject Name: Operating Systems Unit number : 1 Unit Title: Overview of Operating.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Department of Computer Science and Software Engineering
Operating System Concepts
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Chapter 3: Operating-System Structures
Introduction to Operating Systems Concepts
Chapter 4 – Thread Concepts
Introduction to threads
Module 3: Operating-System Structures
OPERATING SYSTEM CONCEPT AND PRACTISE
Processes and threads.
Chapter 3: Process Concept
Credits: 3 CIE: 50 Marks SEE:100 Marks Lab: Embedded and IOT Lab
CS 6560: Operating Systems Design
Chapter 2: Operating-System Structures
Lecture 4: Operating System Structures
Chapter 2: System Structures
Chapter 4 – Thread Concepts
Process Management Presented By Aditya Gupta Assistant Professor
Operating System Structure
Introduction to Operating System (OS)
Java programming lecture one
Lecture 1 Runtime environments.
Chapter 4: Threads.
Chapter 2: Operating-System Structures
Chapter 2: Operating-System Structures
Lecture 2: Processes Part 1
Operating System Concepts
Threads, SMP, and Microkernels
ICS 143 Principles of Operating Systems
Chapter 2: System Structures
Chapter 3: Operating-System Structures
Chapter 1 Introduction to Operating System Part 5
Lecture Topics: 11/1 General Operating System Concepts Processes
Lecture 4- Threads, SMP, and Microkernels
Operating Systems : Overview
Chapter 2: Operating-System Structures
Operating Systems Lecture 1.
Introduction to Operating Systems
Outline Chapter 2 (cont) OS Design OS structure
Chapter 3: Processes.
Chapter 2: Operating-System Structures
CS510 Operating System Foundations
Lecture 1 Runtime environments.
OPERATING SYSTEMS STRUCTURES
System calls….. C-program->POSIX call
System Calls System calls are the user API to the OS
CSE 153 Design of Operating Systems Winter 2019
Chapter 2: Operating-System Structures
Operating System Overview
Presentation transcript:

Lecture 1 RunTime Environments

Administrative Stuff Email: majeek@cs.bgu.ac.il Reception Hour: TBD Course Site: www.cs.bgu.ac.il/~spl191 Assignments: 4 assignments. (in pairs) – 40% (11%,11%,11%,7%) Final Exam – 60%

Course Overview System programming: Mostly writing software that will service other software. Application programming also require system programming skills. A programmer often deals with hardware-level concepts Memory Data transfer Protocols Need to understand runtime environment (RTE) – the environment in which the programs runs. There are a few types of RTE’s but all follow a similar scheme

Course Overview We will review the main services provided by RTEs Memory management. Concurrency in multi-thread and multi-process environments. Object Oriented Design - design patterns, principles and essentials Inter-process communication Networking and TCP/IP mode. Data storage – files/databases Scripting – compiling scripts, execution scripts Application layer protocols, such as HTTP or SSH protocols We will use: C++, Java, Python, SQL

Course Overview Week Lectures Overview 1 RTE and System modeling Runtime Environments, introduction to C++, Java, and Python. 2 C++ Memory Memory Management, Stack and Heap Models, Memory Allocation, Garbage Collector 3 C++ Pointers Pointers, Member Initialization List, lvalue/rvalue References, Parameter Passing, C++ Arrays 4 C++ Objects Objects, Object Construction/Destruction, Rule of Three/Five, C++ Templates, Smart Pointers 5 Java 8 Type Safety, Generics, Lambdas, Class Object 6 TDD and DbC 7 Threads Processes, threads, actors, immutables, Thread safety 8 synchronization, atomics, semaphore, executors, liveness 9 Communication Sockets, multithreading examples (single thread, fixed thread-pool, thread per client), echoProtocol 10 Java NIO, ByteBuffers (changes to accommodate new code) 11 Selector, Flyweight pattern, Reactor pattern (new code) 12 Python/SQL Introduction to Python and SQL 13 Python ORM

The Operating System (OS) The OS is an RTE. Processes – the entities running inside the OS. “programs” or “applications” OS Purpose: Manages hardware resources sharing among the different processes HDD (SSD), RAM, etc Performs basic tasks such as controlling input/output devices, CPU time, facilitating networking and file systems. The entity in the OS that manages these resources is called “kernel”. To interface with the kernel, a process uses “system calls” System calls are low level functions for a process to communicate with the OS

The OS diagram

Process Process- An abstraction for an execution unit. It is an instance of a running program launched from the OS A program – a collection of instructions. Process – the execution of those instructions. There may be many instances of the same program – each one is a process. Thread – launched from inside a process (process code) Each process may have multiple threads Each thread may be executed in parallel We will discuss this extensively in several weeks

Process – OS interaction A process interacts with the OS when hardware resources are needed The main resources the OS manages among all processes: Memory CPU time Disk space Input/Output devices Communication (WiFi/Ethernet/3G) Notification services The interaction can be partitioned into two: Services initiated by the OS CPU time, initial memory allocation to load the program Services requested by the process Memory, disk-space, access to I/O devices

Process Life Cycle: Execution The OS manages the life of a process: Creates the process Manages its execution Terminates the process The user executes a program using an execution command The OS is asked by the user to create a process The OS identifies the executable file for the program The executable file consists of binary instructions, specific for each OS The OS creates the process which runs the executable To execute the process, the operating system: Provides each process a unique id (number) Allocates memory for the process in the main memory (RAM) Loads the executable instructions to the RAM Identifies the “main” function (using the entry point value), and executes it. It can execute it with arguments given by the user or the OS itself.

Process Life Cycle: System Calls System calls are the interface between a program and the OS: Application developers often do not have direct access to the system calls They can access them through an application programming interface (API) The functions that are included in the API invoke the actual system calls

Process Life Cycle: System Calls Programming interface to the services provided by the OS Typically written in a high-level language (C or C++) Three most common APIs are: Win32 API for Windows, POSIX API (all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) There are 5 different categories of system calls: process control file manipulation (and protection) device manipulation information maintenance communication. Functions and system calls look the same but are different: printf(“hello”) vs func1(1,2).

Process Life Cycle: System Calls There are 5 different categories of system calls: Process control Handles process execution/halting File manipulation (and Protection) Handles access to storage devices to manipulate files Device manipulation Manipulation hardware devices such as the monitor, graphics card, keyboard or mouse Information maintenance Storing process meta information, time, date, etc. Communication Inter-process communication and sharing data between them.

Process Life Cycle: System Calls Process control end, abort, load, execute, create process, terminate process, get process attributes, set process attributes, wait for time, wait event, signal event, allocate and free memory File manipulation (and Protection) create file, delete file, open, close, read, write, reposition, get file attributes, set file attributes Device manipulation request device, release device, read, write, reposition, get device attributes, set device attributes, logically attach or detach devices

Process Life Cycle: System Calls Information maintenance get time or date, set time or date, get system data, set system data, get process, file, or device attributes, set process, file, or device attributes Communication (between processes) Inter Process Communication or IPC, can be done via sockets, pipes, shared memory and others. create, delete communication connection, send, receive messages, transfer status information, attach or detach remote devices Example for pipes: ls –l | wc –n 2

System Calls: C++ API

Process Life Cycle: Termination When a process executes “exit()” system call, the process is terminated by the OS as follows: Releases allocated memory space Closes open files (file descriptors) Cancels all pending timers Initiates a final “context switch” from the process Finally, process ID is released, and the process is deleted from the OS process table.

CPU time sharing The CPU executes machine instructions one by one sequentially CPU time is the main resource shared by the processes The OS shares the CPU among all processes executing concurrently That is “multitasking”. “Context switch”: Stop executing one process and switch to another one Context switches are expensive: Each takes the time of about 10,000 “regular” instructions The OS’s “scheduler” is the entity that decides “who runs next”.

CPU time sharing A process may be in several states: New: Recently created, not scheduled yet Ready: Ready to run, but not yet assigned to a processor Running: Actually executing on a processor Waiting: Not currently executing. Not currently able to execute. Won't be runnable until some specific external event occurs, such as an I/O operation. Terminated: Done executing

Types of Programming Languages Interpreted: executed using interpreter, directly from text code! the initial language may be compiled into an intermediate language, which is interpreted. Examples: Python, Bash, Matlab Compiled: directly processed by the machine CPU (native code) text files containing code are translated to machine code though a compiler and a linker. Examples: C, C++ Hybrid: starts with interpreted code and compiled to native code on the fly. Examples: Java

Interpreted vs. Compiled to binary Language Advantages of Interpreted Languages: higher level: and easier to program than compiled languages. Means simpler syntax than compiled languages More portable: can run on any machine/OS that supports the interpreter without any code modifications. Disadvantages of Interpreted Languages: The code can be run only with the interpreter – not “standalone”. Binary codes runs faster than interpreted codes. Although interpreters with runtime optimizations may also be efficient.

Hybrid Language: The Java Virtual Machine The Java Virtual Machine is a process, and acts as an intermediate layer between the Java byte code and the OS. A text file P.java is compiled to a java byte code file P.class. All Java code is (interpreted) executed using the JVM process Java code is not executed via the operating system! This allows Java code to be portable. Interacting with the OS and hardware is done via interacting with the presented JVM objects only. Example: The object system.out represents the JVM support for printing.

Java Just-In-Time (JIT) Compiler  The JVM also contains a Just-In-Time (JIT) compiler While the JVM interpreting the byte code program, highly executed pieces of code are compiled to an optimized native machine code. JIT is what allows the JVM to have a performance that is in many cases comparable with native code. But not always!

Java Program Lifecycle Launch: The JVM is invoked with a parameter which refers to a class file. For example, java P.class. The JVM starts running as a process inside the OS. The JVM loads the class file, and other “imported” classes. The JVM identifies a method static Main(String args[]), parses the command line parameters, and then invokes the Main method with these parameters. Requesting System Calls: When the program requires a service from the JVM, it invokes the corresponding method from the JVM interface. The JVM services are located in the System package. The Java program interacts with the JVM only - it never invokes a system call directly. Exit: When the program executes the System.exit method the JVM cleans up all the resources allocated to the program Only then the JVM process is terminated

The JVM operation environment

Compiled Language: C++ C++ code is compiled directly to machine code! Done by using C++ compiler (named g++). System calls can be directly initiated from the code via given API Executing the compiled code is done by the OS itself, no intermediates Examples: any *.exe file in windows or executable files in linux.

C++ Compiling Procedure Preprocessor: accepts source code(*.cpp); removes comments; add the content of the include files. Compiler: translates source to assembly code (AND, OR, JMP, SUB etc.). Assembler: creates object code (machine code, 0-s and 1-s, *.o files). Linker: links the object files to an executable and creates an executable machine code; marks the main() as the starting point of the execution.

Interpreted Language: Python Simply write the code, and execute it. No compiler needed! Code is mostly shorter, and easy to read Syntax created to be short No types – increases clarity Extensive built in iterators and looping tools. Disadvantages It lacks true multiprocessor support, concurrency is not easy to use Slower in execution speed in comparison to other languages Not suitable for memory intensive tasks

C++ vs Java vs Python Code Length 3-5 times shorter than Java programs TOPIC C++11 Java 8 Python 3.5 Memory Management manual allocation manual deallocation automatic garbage collection automatic allocation automatic deallocation Code Length Longer lines of code as compared to python. About 40% more code in comparison to C++ 3-5 times shorter than Java programs Typing System statically typed, both code and compiler dynamically typed, Interpreter is strongly typed, language is type-free! Compiling Compiled to machine code Compiles to byte code, then interpreted by the JVM Interpreted by the python interpreter Execution Speed(loops, dynamic arrays with numbers, basic math operations) 100% 1176% 1800% Portability Platform dependent, must be recompiled for different platform Platform independent, byte code generated works on every OS. Platform independent, code is interpreted upon execution. Thread Support Built-in support since C++11 It has built-in thread support. No multithreading! Syntax Complexity Defining blocks using {, ending statements using ; Using indentation only.

Summary Our programs interact with the RTE that executes them. The program invokes services provided by the RTE The RTE can send events or change the state of the process as it is running The main responsibilities of an RTE include: Process management (creation, initialization, destruction) Storage management (memory, file, dbms) Communication management Hardware/Devices management Security

Runtime Environments Topics to be Covered: What is a runtime environment (RTE)? Management of memory in a RTE. Management of concurrency in a modern RTE. Communication and networking in a RTE. Data management in a RTE.

Runtime Environments We will compare RTEs: Operating systems – Unix/Windows. Java virtual machine. Other RTEs – V8, CLR. For each RTE, we will define: Which component plays the role of the RTE Which components are entities running inside the RTE.