CSE 451: Operating Systems Section 2 Shells and System Calls.

Slides:



Advertisements
Similar presentations
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Advertisements

CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
1 Processes Professor Jennifer Rexford
1 CSE 451 Section Autumn 2004 Alex Moshchuk Office hours: Tue 1-2, Thu 4:30-5:30 Allen 218 (or lab)
CSE 451 Section Autumn 2005 Richard Dunn Office hours: WTh 3:30-4:20 Allen 216 (or lab)
CS-502 Fall 2006Project 1, Fork1 Programming Project 1 – Fork.
Project 1CS-3013 A-term Programming Project #1 Forking Processes Due Tuesday, September 8, 11:59 PM.
IntroductionCS-3013 C-term Programming Project #1 Forking Processes Due Thursday, January 24, 6:00 PM.
Programming project #1 1 CS502 Spring 2006 Programming Project #1 CS-502 Operating Systems Spring 2006.
CSE 451: Operating Systems Section 2 Interrupts, Syscalls, Virtual Machines, and Project 1.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Simple Shell Part 1 Due date (75%): April, 2002 Part 2 Due date (25%): Apr 5, 2002.
Project 1, Command Shell CS-502 (EMC) Fall Programming Project #1 Command Shell CS-502, Operating Systems EMC, Fall 2009 (Slides include materials.
UNIX and Shell Programming (06CS36) Unit 1 Continued… Shrinivas R. Mangalwede Department of Computer Science and Engineering K.L.S. Gogte Institute of.
Chapter 1 Introduction 1.1 What is an operating system
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Chapter 2: Linux & POSIX “She sells bash shells by the C shore”
Creating and Executing Processes
CSE 451 – Operating Systems Section, Autumn 2003 TAs: Mike Swift Adrienne Noble
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
System calls for Process management
CSE 451: Operating Systems Section 3: Project 0 recap, Project 1.
Operating Systems Process Creation
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Process Management Azzam Mourad COEN 346.
Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
CSCI 330 UNIX and Network Programming
CSE451 Section 2: Spring 2006 Kurtis Heimerl, YongChul Kwon
System calls for Process management Process creation, termination, waiting.
Chapter Eight Exploring the UNIX Utilities. 2 Lesson A Using the UNIX Utilities.
1 CSE 451 Section 2: Processes, the shell, and system calls.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
CSE 451 Section Autumn 2004 Alex Moshchuk Office hours: Tue 2-3, Thu 4:30-5:30 Allen 216 (or lab)
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
CSE 451 Section #3 Project 0 Recap Project 1 Overview
Implementation of a simple shell, xssh
Implementation of a simple shell, xssh (Section 1 version)
CSE 451 Section 2: Processes, the shell, and system calls
Implementation of a simple shell, xssh
Unix Process Management
UNIX System Overview.
Operating Systems Georgios Varsamopoulos
The Linux Operating System
Unix Operating System (Week Two)
CSE 303 Concepts and Tools for Software Development
CS-3013 & CS-502 Operating Systems Summer 2006
Process Programming Interface
Programming Project #1 Command Shell
CSE 451 Section 2 – Winter 2006.
Programming Project #1 Fork and Command Shell
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
CSE 451 Section 2 - Spring 2005.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Process Description and Control in Unix
Process Description and Control in Unix
EECE.4810/EECE.5730 Operating Systems
Intro to the Shell with Fork, Exec, Wait
Presentation transcript:

CSE 451: Operating Systems Section 2 Shells and System Calls

OSDI /7/102 Finding a Needle in a Haystack: Facebook’s Photo Storage

OSDI /7/103 Results: storage costs reduced 28%; 4x greater read throughput

Project 0  How is it going? 10/7/104

Project 1  Two main parts:  Write a simple shell in C  Add a simple system call to Linux kernel  You’ll learn:  How system calls work in Linux  How to work inside the Linux kernel  Due: Monday Oct 18, 11:59pm  Electronic turnin: code + writeup 10/7/105

Project 1  groups to Abdul & Pete by Monday October 11  After that, assigned to random groups  One turnin per group  Use CVS for version control  es/cse451/10au/projects/cvs.html es/cse451/10au/projects/cvs.html 10/7/106

System calls 10/7/107

System calls  Mechanism for applications to request service from the OS  How do library calls differ from system calls? 10/7/108

System calls vs. library calls Image from: 10/7/109

System calls vs. library calls  Good example: exec family of calls  Library calls: execl, execlp, execle, execv, execvp  All map to one system call: execve  Useful tools  ltrace  strace 10/7/1010

Project 1: adding a system call  Add execcounts system call to Linux  Purpose: count the number of times that some other system calls are called  Steps:  Modify kernel to track these counts  Implement execcounts function in kernel  Add it to the system call table  Call it from your shell, print results 10/7/1011

Shells 10/7/1012

Shells  Primary responsibilities:  Parse user commands  Execute commands / programs  Manage input and output streams  Job control  Examples:  UNIX: bash, csh, …  Windows: Command Prompt, PowerShell 10/7/1013

The UNIX shell  Internal (built-in) commands  Execute routines embedded in the shell  Manage state of the shell (e.g., current working directory, environment variables)  External programs  How can you tell external from internal? 10/7/1014

Other UNIX shell capabilities  Redirect standard input / output / error streams #./parser outfile 2> errfile  Command pipelines # ps –ef | grep java | awk ‘{print $2}’  Background execution of process # time make > make.out & # jobs [1]+ Running time make > make.out & 10/7/1015

The CSE451 shell CSE451Shell% /bin/date Fri Jan 16 00:05:39 PST 2004 CSE451Shell% pwd /root CSE451Shell% cd / CSE451Shell% pwd / CSE451Shell% exit 10/7/1016

The CSE451 shell  Repeat these steps:  Print out prompt  Read and parse input  If built-in command:  Do it directly  Else (external program):  Launch specified program in new process  Wait for it to finish 10/7/1017

Shell system calls  fork  Create a child process  execve  Execute a specified program  wait  wait until child process terminates 10/7/1018

Project 1: final product 10/7/1019 CSE451Shell% execcounts clear CSE451Shell% cd / CSE451Shell% pwd / CSE451Shell% date Wed Sep 29 16:52:41 PDT 2004 CSE451Shell% time Usage: time [-apvV] [-f format] [-o file] [--append] [-- verbose] […] CSE451Shell% execcounts Statistics: Fork: 3 27% VFork: 0 0% Clone: 0 0% Exec: 8 72% CSE451Shell% exit

Project 1: shell hints  Useful library functions (see man pages):  Strings: strcmp, strncpy, strtok, atoi  I/O: fgets  Error reporting: perror  Environment variables: getenv 10/7/1020

Programming in kernel mode  Your shell will operate in user mode  Your system call code will be in the Linux kernel, which operates in kernel mode  Be careful - different programming rules, conventions, etc. 10/7/1021

Programming in kernel mode  Can’t use application libraries (i.e. libc); can only use functions defined by kernel  Can’t use printf, for example: use printk instead  Different set of header files  Can’t trust user space  Unsafe to directly access a pointer passed from user space  More details later 10/7/1022

Linux development hints  No man pages for Linux kernel functions!  Documentation/ directory in kernel source code  “The code is the documentation” 10/7/1023

Navigating Linux code  Invaluable tools:  ctags  cscope  Linux Cross Reference (LXR)  /7/1024

Computing resources  Develop your code on forkbomb  Test your code on VMware PCs in 006  Do not use attu 10/7/1025

VMware  Software simulation of x86 architecture  Run an OS in a sandbox  Easily reset to known good state 10/7/1026

Using VMware  Go through project setup first  es/cse451/10au/projinfo.htm es/cse451/10au/projinfo.htm 10/7/1027

Using VMware 10/7/1028 Power on /off, reset VMWare config: don’t change!

Using VMware  All disks are non-persistent  Powering off loses your changes!  To reboot:  shutdown –r now 10/7/1029

Using VMware  There is only one user: root (password: rootpassword)  You will need to:  Build a Linux kernel image on forkbomb  Run VMware Player on Windows or Linux desktop  Transfer kernel image to VM (use scp)  Boot your kernel in VM 10/7/1030

Legends of computer science  Andrew Tanenbaum: in class tomorrow!  Come early to get a seat 10/7/1031

10/7/1032