Operating Systems Recitation 1, March 10-11 th, 2002.

Slides:



Advertisements
Similar presentations
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Advertisements

Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
January 13, Csci 2111: Data and File Structures Week1, Lecture 2 Basic File Processing Operations.
CS 241 Section Week #5 2/23/12. 2 Topics This Section MP4 overview Function Pointers Pthreads File I/O.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
The ‘system-call’ ID-numbers How can Linux applications written in assembly language create and access files?
CS 311 – Lecture 09 Outline Introduction to Systems programming – System calls – Categories of system calls Error Management System calls File Handling.
1 System Calls & Stdio. 2 Two processes open the same file Both keep writing to it What happens?
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
1 Advanced programming in UNIX 1 File I/O Hua LiSystems ProgrammingCS2690File I/O.
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
Operating Systems Recitation 11, June 9-10, 2002.
1 System Calls and Standard I/O Professor Jennifer Rexford
CSE 451 Section 4 Project 2 Design Considerations.
NCHU System & Network Lab Lab 13 File I/O & Standard I/O.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Adv. UNIX: lowIO/161 Advanced UNIX v Objectives –look at low-level operations for handling files Special Topics in Comp. Eng. 2 Semester.
Fundamentals CIS 552. Fundamentals Low-level I/O (read/write using system calls)  Opening/Creating files  Reading & Writing files  Moving around in.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 5 Acknowledgements: The syllabus and power point presentations are modified versions.
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
Recitation 9: Error Handling, I/O, Man Andrew Faulring Section A 4 November 2002.
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
1 System Programming Chapter 3 File I/O. 2 Announcement The first exercise is due today. We will NOT accept late assignment this time. –Submission site.
UNIX Files File organization and a few primitives.
NCHU System & Network Lab Lab 11 Memory Mapped File.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Week 12 - Wednesday.  What did we talk about last time?  File I/O  Binary trees  Lab 11.
Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls.
Operating Systems Recitation 4, April th, 2002 Signals.
Advanced Programming in the UNIX Environment Hop Lee.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Linux File system Implementations
Laface 2007 File system 2.1 Operating System Design Filesystem system calls buffer allocation algorithms getblk brelse bread breada bwrite iget iput bmap.
Recitation 9: Error Handling, I/O, Man Anubhav Gupta Section D.
January 7, 2003Serguei Mokhov, 1 File I/O System Calls Reference COMP 229, 444, 5201 Revision 1.2 Date: July 21, 2004.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Tarek Abdelzaher Vikram Adve CS241 Systems Programming System Calls and I/O.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem.
OS interface: file and I/O system calls File operations in C/C++? –fopen(), fread(), fwrite(), fclose(), fseek() in C f.open(…), f.close(…) in C++ I/O.
CS 241 Section Week #5 9/22/11. 2 Topics This Section File I/O Advanced C.
CSC 271 – Software I: Utilities and Internals An Introduction to File I/O in Linux Credited to Dr. Robert Siegfried and Beginning Linux Programming by.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Overview Dr. Xiao Qin Auburn University
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
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 -
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Error handling I/O Man pages
Operating Systems Moti Geva
Lecture 31: Introduction to File System
Advanced Unix Programming
Chapter 7 Text Input/Output Objectives
UNIX System Overview.
System Structure B. Ramamurthy.
Operating System Hebrew University Spring 2004
An overview of the kernel structure
Unix Directories unix etc home pro dev motd snt unix ... slide1 slide2
System Structure and Process Model
CSE 333 – Section 3 POSIX I/O Functions.
Introduction Paul Flynn
File I/O (1) Prof. Ikjun Yeom TA – Mugyo
CSE 333 – Section 3 POSIX I/O Functions.
Advanced UNIX progamming
CSE 333 – Section 3 POSIX I/O Functions.
FILE I/O File Descriptors I/O Efficiency File Sharing
Lab 10 Paging.
Unix Directories unix etc home pro dev motd snt unix ... slide1 slide2
Presentation transcript:

Operating Systems Recitation 1, March th, 2002.

Course staff מרצים: סיון ענת מתרגל: עדו בודקים: mailbox ניר נוימרק mailbox אלעד

References Operating Systems Sivan Toledo (Akademon, 2001) Sivan Toledo Operating System Concepts Abraham Silberschatz, Baer Peter Galvin, Greg Gagne (John Wiley & Sons, 2001) Abraham SilberschatzBaer Peter GalvinGreg Gagne Advanced Programming in the UNIX Environment W. Richard Stevens (Addison Wesley, 1992) W. Richard Stevens Understanding the Linux Kernel Daniel P. Bovet, Marco Cesati (O'Reilly, 2000) Daniel P. BovetMarco Cesati

Course structure Three elements –Lectures –Recitations –Programming exercises

Course structure Lectures Sunday, 16:00-19:00, Orenstein 103. Monday, 16:00-19:00, Dan David 001. Recitations Group 11: Sunday, 19:00-20:00, Shenkar 222. Group 10: Monday, 12:00-13:00, Kaplun 118. Group 07: Monday, 15:00-16:00, Kaplun 118. Group 08: Monday, 19:00-20:00, Shreiber 06. Reception: Sunday, 11:00-12:00, Schreiber 20M. Webpage

Course requirement weekly C programming exercises Linuxwww.linux.orgwww.linux.org free Unix-type operating system several distributions ( Final exam includes 1-2 questions regarding the programming exercises. Programming exercises are mandatory and grant 5-10 bonus points in final grade.

Exercise submission guidelines Software –Directories: under your home directory create a subdirectory called os02b. There, for each exercise create a subdirectory, with the same name as the exercise program file. There, submit the exercise. –Files: submit all.c files,.h files if any, makefile ONLY –Permissions: read and execution permissions to user, group and others, for both directories and files after exercise submission: chmod ugo+rx Hardcopy –name, ID, login, CID (returned with 1 st graded exercise) –.c files –Answers to additional questions.

Introduction

Programs and processes A program is an executable file residing on disk. It is read into memory and executed by the kernel as a result of an exec function. An executing instance of a program is called a process. Every Unix process has a unique identifier, a nonnegative integer.

System calls and library functions application code C library functions system calls kernel user process

System calls and library functions application code memory allocation function malloc sbrk system call kernel user process

File I/O technical details

File I/O Most Unix file I/O can be performed using only five functions: open, read, write, lseek, close. We will examine the effect of different buffer sizes on the read and write functions.

File descriptors To the kernel all open files are referred to by file descriptors – non negative integers. When we open an existing file or create a new file, the kernel returns a file descriptor to the process. When we want to read or write a file, we identify the file with the file descriptor that was returned by open. Convention, Unix shells associate file descriptor 0 standard input, 1 standard output, 2 standard error

open A file is opened or created by calling the open function #include primitive system data types #include file status #include file control … int open(const char *pathname, int flags, int mode) Returns a file descriptor if OK, -1 on error. pathname is the name of the file to open or create. The options for this function are specified by the flags argument, which is formed by OR’ing together constants, one of the following must be specified: O_RDONLY open for reading only, O_WRONLY open for writing only, O_RDWR open for reading and writing Optional constants include: O_APPEND append to the end of file on each write O_CREAT create the file if it doesn’t exist O_EXCL gives an error if O_CREAT is specified and the file exists

close An open file is closed by #include symbolic constants … int close(int filedes) Returns 0 if OK, -1 on error Closing a file also releases any record locks that a process may have on the file. When a process terminates, all open files are automatically closed by the kernel.

read Data is read from an open file with the read function #include … ssize_t read(int filedes, void* buff, size_t nbytes) Returns number of bytes read, 0 if end of file, -1 on error. The data that is read is stored in the buffer whose address is specified in buff and size indicated by nbytes.

write Data is written to an open file with the write function #include … ssize_t write(int filedes, const void *buff, size_t nbytes) Returns the number of bytes written if OK, -1 on error. The return value is usually equal to the nbytes argument, otherwise an error has occurred. A common cause for a write error is either filling up a disk or exceeding the file size limit for a given process. Write start at the file’s current offset. If the O_APPEND option was specified in the open, the file’s offset is set to the current end of file before each write operation. After a successful write, the file’s offset is incremented by the number of bytes actually written.

lseek Every open file has an associated offset, a non- negative integer that measures the number of bytes from the beginning of the file. Read and write operations start at the current file offset and increment it by the number of bytes read or written. By default, this offset is initialized to 0 when a file is opened, unless the O_APPEND option is specified.

lseek An open file can be explicitly positioned #include … off_t lseek(int filedes, off_t offset, int whence) Returns new file offset if OK, -1 on error. The interpretation of the offset depends on the value of the whence argument –SEEK_SEToffset bytes from beginning of file –SEEK_CURcurrent value + offset –SEEK_ENDsize of file + offset

File sharing Unix supports sharing of open files between different processes. Three data structures are used by the kernel for I/O: 1.Every process has an entry in the process table. Within each process table entry is a table of open file descriptors, a vector, with one entry per descriptor. 2.The kernel maintains a file table for all open files. Each file table entry contains: file status flag (read, write, append), current file offset, pointer to v-node table entry. 3.Each open file has a v-node structure: file type, pointers to functions that operate on the file. File owner, size, device, position on disk.

process table entry fd 0: fd 1: fd 2: fd 3: flags ptr... process table entry fd 0: fd 1: fd 2: fd 3: fd 4: flags ptr... file status flag current file offset v-node ptr file table file status flag current file offset v-node ptr v-node table information current file size Two independent processes have the same file open The first process has the file open on descriptor 3, and the 2 nd process has the same file open on descriptor 4. Each process that opens the file gets its own file table entry, but only a single v-node table entry for a given file. each process has its own current offset for the file

After each write the current file offset in the file table entry is incremented by the number of bytes written. lseek only modifies the current file offset in the file table entry, no I/O takes place.

File system calls – exercise 1 Write and run a simple C program on Linux, that copies a file, using the basic file system calls. The program should print an error message if there are not enough arguments (printf and exit), if the input file does not exist or if the output file already exists (perror). The program should use the system calls described except for lseek. Copying should be performed using a buffer size of n bytes. The program should accept three arguments, the input filename, output filename, and n (which is the buffer size).

Exercise 1 - notes In order to turn the string that contains the buffer size into an integer, you can call sscanf(argv[3], “%d”, &n)in stdio.h Use malloc to allocate storage for the buffer #include utility functions … char* buffer;... buffer = (char*) malloc(n);

Time values Clock time – the amount of time a process takes to run. This depends on the number of other processes being run on the system. Whenever you report the clock time, the measurements should be made with no other activities on the system. User CPU time – attributed to user instructions. System CPU time – attributed to the kernel when it executes on behalf of a process. For example, whenever a process executes a system service, such as read or write, the time spent within the kernel performing that system service is charged to the process. To measure times for any process, execute the time command with the argument to the time command being the command to measure.

Exercise 1 - timing Measure the running time of your program using the time command, when copying a file of size 1MB: Measure the running time for buffer sizes (in bytes): 1, 64, 512, 1024, 8192, Is there a considerable difference between the running times with different buffer sizes? If so, explain why.

Exercise 1 Chapter 2.8, pages 41-44, in Toledo’s book. Submission deadline: Friday, March 22 nd. Software directory: ~username/os02b/ex-rw/ files: ex-rw.c permissions: chmod ugo+rx (to above) Hardcopy – submit ONLY what is required. name, ID, login, CID (upon return of 1 st exercise) ex-rw.c answers to timing questions. submit in mailbox 281, Nir Neumark, Schreiber Bldg. Reference: chapter 3, pages 47-60, in Stevens book.