Operating System Labs. Yuanbin Wu

Similar documents
Processes. Dr. Yingwu Zhu

Unix Processes. What is a Process?

Process Management! Goals of this Lecture!

Process Management 1

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

COMP 3430 Robert Guderian

SOFTWARE ARCHITECTURE 3. SHELL

1/13/2019 Operating Systems. file:///volumes/users/rasit/desktop/comp3430/coursematerial/slides/03_processes/index.html?

Processes. CS3026 Operating Systems Lecture 05

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Fall 2015 COMP Operating Systems. Lab #3

Operating systems and concurrency - B03

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

CS 3733 Operating Systems

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

CSC 1600 Unix Processes. Goals of This Lecture

W4118 Operating Systems. Junfeng Yang

Processes COMPSCI 386

ESE 333 Real-Time Operating Systems 2 What is an operating system? Two views: 1. Top-down view: Extended machine ffl Covers the details of the hardwar

CS 31: Intro to Systems Processes. Kevin Webb Swarthmore College March 31, 2016

Chap 4, 5: Process. Dongkun Shin, SKKU

TCSS 422: OPERATING SYSTEMS

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Design Overview of the FreeBSD Kernel CIS 657

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Operating Systems. Review ENCE 360

CS240: Programming in C

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

Exam Guide COMPSCI 386

518 Lecture Notes Week 3

(MCQZ-CS604 Operating Systems)

3. Process Management in xv6

(In columns, of course.)

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Midterm Exam CPS 210: Operating Systems Spring 2013

Operating System Structure

Mon Sep 17, 2007 Lecture 3: Process Management

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

CSE 153 Design of Operating Systems Fall 2018

Operating Systems and Networks Assignment 2

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

Inter-Process Communication

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Exceptional Control Flow Part I September 22, 2008

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Chapter 3: Process Concept

Chapter 3: Process Concept

4. The Abstraction: The Process

Exceptional Control Flow Part I Oct. 17, 2002

COP4342 UNIX Tools Assignment #3: A Simple Unix Shell. Instructor: Dr. Robert Van Engelen Teaching Assistant: Imran Chowdhury Spring 2018

Chapter 3: Process Concept

Processes and Threads

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

High Performance Computing Lecture 11. Matthew Jacob Indian Institute of Science

A2 Design Considerations. CS161, Spring

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

Process Management! Goals of this Lecture!

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Processes. Process Concept

Announcement. Exercise #2 will be out today. Due date is next Monday

Operating Systems CS 571

Operating System Design

Concurrent Processing in Client-Server Software

Jan 20, 2005 Lecture 2: Multiprogramming OS

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow

Processes. Sanzheng Qiao. December, Department of Computing and Software

A process. the stack

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Processes. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

What is a Process? Processes and Process Management Details for running a program

CSC369 Lecture 2. Larry Zhang

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

OPERATING SYSTEMS: Lesson 4: Process Scheduling

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Problem Set: Processes

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

csci3411: Operating Systems

Processes. CS439: Principles of Computer Systems January 30, 2019

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

Operating Systems. II. Processes

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

fork System-Level Function

Exceptional Control Flow Part I

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Transcription:

Operating System Labs Yuanbin Wu cs@ecnu

Anouncement Project 1 due 21:00 Oct. 4th FTP In campus: direct connection Out of campus: VPN Windows: cmd \\222.204.249.4:5010 Linux: ftp 222.204.249.4 5010

Operating System Labs Review of process Concept API introduction Project 2

Virtualizing the CPU Multi-task How to provide the illusion of many CPUs? Time sharing

The abstraction: Running programs What does a process consist of? CPU Program Counter (PC) Stack Pointer / Frame Pointer Memory Address space Disk Set of file descriptors

What does a process consist of? proc file system Example cat /proc/<pid>/status cat /proc/<pid>/maps cat /proc/<pid>/fd cat /proc/<pid>/io Provide a method of communication between kernel space and user space ps command

API Create Destroy Wait Misellaneous Control Get status

Details of process creation Load code and static data Establish stack Init heap local variables, function calls malloc, free Allocate file descriptors STDIN_FILENO STDOUT_FILENO STDERR_FILENO

States

States

Data structures

Virtualizing the CPU Low level mechanisims Context switch High level intelligence Scheduling policy

Low level mechanisims Direct Execution Just run a programm on CPU directly

Problems of direct execution No control Visit any memory address Open any file Directly play with hardwares (e.g. I/O)

Limited Direct Execution Kernel model and user model restricted operations By the kernel When a thread need do restricted operations System call

Limited Direct Execution Need some hardware supports A bit in CPU identifies kernel/user mode trap instruction return-from-trap instruction Save the regs before do the restricted operation (kernel stack)

Switching between processes Cooperative approach OS trusts the process to yield CPU properly Incooperative approach OS revokes the control of CPU periodically Time interrupt Scheduler

Low-level mechanisims: summary Direct execution Limited direct execution Switch between processes

High level intelligence Schedulling policy First In, First Out Shortest job first Shortest time to complete first Round Roubin

Summary of CPU virtualization Low level mechanisims A little hardware support goes a long way Hige level mechanisims

API fork(), exec(), wait(), exit() Create, execute, wait and terminate a process May be the strangest API you've ever met

API fork() Create a new process Exactly copy the calling process The return code of fork() is different In parent: fork() return the pid of the child In child: fork() return 0 Who will run first is not determined

API wait() Wait for child to finish his job The parent will not proceed until wait() return. waitpid()

API exec() Execute a different program in child process A group of system calls: execl, execv, execle, execve, execlp, execvp, fexecv

Some Coding fork fork, wait fork, wait, execvp

What's happening behind fork()? The child get a copy of parent's data space, stack, heap the system call: clone() Copy-on-write Not really copy the data, but share the data with read only flag If parent or child writes on a shared address, the kernel make a copy of that piece of memory only (usually a page)

What's happening behind fork()? File sharing fd File offsets

What's happening behind fork()? Other shared data: User ID, group ID Current working directory Environment Memory mapping Resources limits...

What's happening behind exit()? Close all fds, release all memory, Inform the exit status to the parent process, which can be captured by wait()

What's happening behind wait()? The parent terminates first? The init process (PID=0) The child terminates first? The kernel keeps a small amount of information for every terminating process Available when the parent calls wait() PID, termination status, the amount of CPU time zombies

What's happen behind wait()/waitpid() wait(): block the caller until a child process terminates waitpid(): wait which child, and some other options

What's happening behind exec()? Replace the current process with a new program from disk Text, data, heap, stack Start from the main() of that program

API summary fork(): create a new process wait(): wait for a child exit(): destroy a process exec(): execute a programm in child

Project2 Implement your own shell Use fork, wait, execvp Also open, close, dup2

Project2 Details Basic shell Run your shell by:./mysh It will print a prompt: mysh> You can type some commands mysh> ls Hit ENTER, the command will be executed

Project2 Details Build-in Commands When mysh execute a command, it will check wether it is a build-in or not. For build-in commands, you should involve your implementation. They are: exit wait cd pwd

Project2 Details Redirection Your shell should support redirection: mysh> ls -l > output The file output contain the result of ls -l

Project2 Details Background Jobs Your shell should be able to run jobs in the background mysh> ls & Your shell will continue to work rather than wait.

Project2 Details Batch mode Your shell should be able to run in batch mode./mysh batch_file Your shell will run the commands in batch_file E.g, batch_file contains ls -l cat batch_file

Project2 Details Bonus: Pipe The pipe connect the input/output of different commands mysh> grep hello FILE wc -l How many lines have hello