CS/COE 0449 (term 2174) Jarrett Billingsley

Slides:



Advertisements
Similar presentations
Discussion Week 4 TA: Kyle Dewey. Overview Project #1 debriefing System calls Project #2.
Advertisements

Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
CSE 451 Section 4 Project 2 Design Considerations.
Linux Operating System
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
CSCC69: Operating Systems Assignment 3 Review. Assignment Review Implement the file-related system calls – open, close, dup2 – read, write, lseek – chdir,
RjpSystem Level Programming Operating Systems 1 Having fun withy the Unix Operating System Praxis Week 7 Rob Pooley.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Chapter 1 Introduction 1.1 What is an operating system
Recitation 9: Error Handling, I/O, Man Andrew Faulring Section A 4 November 2002.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
CS162B: Pipes Jacob T. Chan. Pipes  These allow output of one process to be the input of another process  One of the oldest and most basic forms of.
UNIX Files File organization and a few primitives.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Agenda  Redirection: Purpose Redirection Facts How to redirecting stdin, stdout, stderr in a program  Pipes: Using Pipes Named Pipes.
CS 346 – Chapter 2 OS services –OS user interface –System calls –System programs How to make an OS –Implementation –Structure –Virtual machines Commitment.
System Interface Interface that provides services from the OS (Higher than BIOS) Memory Scheduler File/Storage System Inter-process Communication and Network,
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
File Systems cs550 Operating Systems David Monismith.
CSCC69: Operating Systems Tutorial 10. Hints on testing Assignment 3 How to test tlb replacement algorithms? – Write a program that creates an array larger.
Recitation 9: Error Handling, I/O, Man Anubhav Gupta Section D.
Recitation 9: 11/04/02 Outline Error Handling I/O Linux man pages Annie Luo Office Hours: Thursday 6:00 – 7:00 Wean 8402.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Overview Dr. Xiao Qin Auburn University
Files in UNIX u UNIX deals with two different classes of files:  Special Files  Regular Files u Regular files are just ordinary data files on disk -
Using Linux Kaya Oğuz Room: 310.
Week 12 - Thursday CS222.
Programs – Preprocessing, Compilation and Linking
Error handling I/O Man pages
Unix Basics.
CS/COE 0449 (term 2174) Jarrett Billingsley
Programs – Loading and Running an Executable
Week 12 - Wednesday CS222.
CASE STUDY 1: Linux and Android
Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command Some by invocation from other running.
The Linux Operating System
OS – Process Creation and Destruction
Lecture 11 bash scripting overview c programming overview moving data between c and bash memory and pointers.
Programs – Dynamic Linking and Loading
stdin, stdout, stderr Redirection
CS/COE 0449 (term 2174) Jarrett Billingsley
Week 4 - Monday CS222.
Threads and Cooperation
Programs – Dynamic Linking and Loading
Lecture 5: Process Creation
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Kernel – Device Drivers (part 1)
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S
CSE 333 – Section 3 POSIX I/O Functions.
Shells, Help, and Paths.
2/25/08 Frans Kaashoek MIT OS abstractions 2/25/08 Frans Kaashoek MIT
Exploring Shell Commands, Streams, and Redirection
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
OS – Memory Deallocation
IPC Prof. Ikjun Yeom TA – Hoyoun
CS/COE 0449 Jarrett Billingsley
Advanced UNIX progamming
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
CSE 333 – Section 3 POSIX I/O Functions.
Programs – Loading and Running an Executable
CSCI 380: Operating Systems William Killian
Low-Level I/O – the POSIX Layer CSE 333 Winter 2019
Department of Computer Science
Exploring Shell Commands, Streams, and Redirection
Presentation transcript:

CS/COE 0449 (term 2174) Jarrett Billingsley OS – POSIX System Calls CS/COE 0449 (term 2174) Jarrett Billingsley

Class announcements Project 2 due tomorrow by midnight! How many of you did program 2? Are you sure your password is right? Maybe you should check to be sure. Don’t forget, you can resubmit (_1, _2 etc.) So for project 3 (the next one, over spring break)… Due date of the 13th is too soon. So would you rather have it due… The same day as the exam (3/16)? Or the day after the exam (3/17)? Yeah I thought so 2/28/2017 CS/COE 0449 term 2174

System Calls, continued 2/28/2017 CS/COE 0449 term 2174

Language Runtime (libc, msvcrt, JRE) Layer cake User-space applications usually look like this: These layers in the middle do a good bit of work trying to make as few system calls as possible. Remember stdio buffering? The public OS API can do some fun user-space stuff itself, but is mostly a bunch of wrapper functions: functions which perform the system call in a platform-independent way. User Space Kernel Program code Language Runtime (libc, msvcrt, JRE) Public OS API (POSIX, Win32) OS Kernel Syscall Handler 2/28/2017 CS/COE 0449 term 2174

The POSIX API 2/28/2017 CS/COE 0449 term 2174

The POSIX API POSIX stands for Portable Operating System Interface. (the X just looks cool.) POSIX was defined as a universal API for all the flavors of UNIX, which Linux (mostly) implements as well. This is why it was needed. 2/28/2017 CS/COE 0449 term 2174

Everything’s a file! One of the most UNIX-y concepts that POSIX inherits is that pretty much every computer/OS resource is represented as a file. Hard drives? Files. Displays? Files. Keyboards? Files. Processes? Files. Files?.............................. Files. Let’s look at /proc, /dev, and /sys! 2/28/2017 CS/COE 0449 term 2174

The big unifying concept Everything on the system is represented in this big tree. The root of this tree is is /, which is called… the root directory. The internal nodes are directories, and the leaves are files. Directory names always end in a /. We can also have symbolic links. These are “fake” files which serve as an alias for another file or directory. For example, when we access /bin/sh on thoth, it’s really accessing /bin/bash. / dev/ bin/ usr/ sh bash tar 2/28/2017 CS/COE 0449 term 2174

Accessing the “file” system Unsurprisingly – considering C and UNIX’s relationship – the POSIX system calls for accessing files look a lot like C’s. int open(const char* filename, int flags); int read(int fd, void* buffer, size_t size); int write(int fd, const void* buffer, size_t size); int close(int fd); Things to note: There is no mention of FILE*. FILE* is an abstraction that the C stdio library gives us on top of these functions. Instead, open returns an int, and read/write/close all take an int to specify which file to operate on. This is called a file descriptor, but it’s just a number. 2/28/2017 CS/COE 0449 term 2174

Watching it go We can see all the system calls a program makes as it runs using the strace command. Let’s strace a simple “hello world” program. execve is the call the actually runs the program. (sorta.) brk is one way to dynamically allocate heap memory. Here it seems to be using it to ask where the heap begins. mmap (memory map) is a more modern way to dynamically allocate memory, and can also be used to read/write files. It’s part of the virtual memory system. mprotect lets you change the access rights on memory areas. munmap gives the mapped memory pages back to the OS. fstat gets information about an open file. 2/28/2017 CS/COE 0449 term 2174

The standard input/output/error files Every process on a POSIX system is given these three files when it starts. By default, stdin is hooked up to the keyboard and stdout/err are hooked up to the terminal display. But you can change that! On the shell, you can redirect stdout to a file like so: ./command > output stderr can be redirected like this (notice the 2!): ./command 2> output You can output BOTH to the same file like this: ./command &> output And you can redirect stdin like this: ./command < file_to_read Name Descriptor stdin stdout 1 stderr 2 POSIX calls close(); dup() dup2() 2/28/2017 CS/COE 0449 term 2174

wordswordswordswordswordswordswordswordswordswords World 7 You can even chain programs together with the pipe | character. This is Shift+\ on American English keyboards. Let’s try ps aux | less Here’s what’s happening: pipe() stdout stdin ps aux less wordswordswordswordswordswordswordswordswordswords 2/28/2017 CS/COE 0449 term 2174