Advanced UNIX progamming

Slides:



Advertisements
Similar presentations
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
Advertisements

January 13, Csci 2111: Data and File Structures Week1, Lecture 2 Basic File Processing Operations.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
CS 311 – Lecture 09 Outline Introduction to Systems programming – System calls – Categories of system calls Error Management System calls File Handling.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
Linux+ Guide to Linux Certification, Second Edition
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
1 Friday, July 07, 2006 “Vision without action is a daydream, Action without a vision is a nightmare.” - Japanese Proverb.
CSE 451 Section 4 Project 2 Design Considerations.
Linux Operating System
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 5 Acknowledgements: The syllabus and power point presentations are modified versions.
Linux+ Guide to Linux Certification, Second Edition
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
Chapter 2: Linux & POSIX “She sells bash shells by the C shore”
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.
File System Implementation
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
CE Operating Systems Lecture 17 File systems – interface and implementation.
Advanced Programming in the UNIX Environment Hop Lee.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Linux File system Implementations
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 9 Acknowledgements: The syllabus and power point presentations are modified versions.
Operating Systems, Spring 2003 Local File Systems in UNIX Ittai Abraham Zinovi Rabinovich (recitation)
Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally FILE SYSTEM.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 28 Acknowledgements: The syllabus and power point presentations are modified versions.
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
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.
W4118 Operating Systems Instructor: Junfeng Yang.
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
CS/COE 0449 (term 2174) Jarrett Billingsley
Introduction to Kernel
Today topics: File System Implementation
Operating Systems Moti Geva
Advanced UNIX progamming
UNIX System Overview.
CS 3733 Operating Systems Topics: IPC and Unix Special Files
Lecture 5: Process Creation
Files I/O, Streams, I/O Redirection, Reading with fscanf
Chapter 11: File System Implementation
An overview of the kernel structure
Topics Introduction to File Input and Output
Chapter 2: The Linux System Part 2
Chapter 2: System Structures
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Advanced UNIX programming
FILE I/O File Descriptors I/O Efficiency File Sharing
Topics Introduction to File Input and Output
Advanced UNIX programming
Introduction to Operating Systems
The UNIX Time Sharing System
Presentation transcript:

Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 6 Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan

Announcements Reading assignment APUE Chapter 3 APUE Chapter 4 Pages 47-56, 56-62 APUE Chapter 4 Pages 77-81, 92-95 APUE Chapter 5

Review Portability Introduction to the UNIX API UNIX file system Standards: ANSI, POSIX, etc 32 bit vs 64 bit Byte order: Little endian vs big endian Introduction to the UNIX API Environment variables Exit status Process ID User ID UNIX file system File system abstraction Directories File descriptors

Week 3 Topics UNIX file system File system abstraction Directories File descriptors Unix API Programming Examples and Techniques Example with direct IO open, close, fdopen, lseek, unlink Variable argument list HW1 hints

Week 3 Topics ... continued File I/O Process management Pipes File descriptors open, creat, close, dup, dup2 I/O redirection Process management fork, exit, wait, waitpid, execv Pipes Named and unnamed pipes Implementing pipe in a shell

UNIX file system File system abstraction Directories File descriptors

File system abstraction File: a sequence of bytes of data Filesystem: a space in which files can be stored Link: a named logical connection from a directory to a file Directory: a special kind of file, that can contain links to other files Filename: the name of a link Pathname: a chain of one or more filenames, separated by /'s

File system abstraction ... continued inode: a segment of data in a filesystem that describes a file, including how to find the rest of the file in the system File descriptor: a non-negative integer, with a per-process mapping to an open file description Open file description: an OS internal data-structure, shareable between processes

Directories

Directories ... continued Names belong to links, not to files There may be multiple hard links to one file Renaming only renames one link to that file Unix allows both hard and soft links A file will exist even after the last hard link to it has been removed, as long as there are references to it from open file descriptions Soft links do not prevent deletion of the file A directory may have multiple (hard) links to it But this capability is usually restricted, to prevent creation of directory cycles

File Descriptors Each open file is associated with an open file description Each process has a (logical) array of references to open file descriptions Logical indices into this array are file descriptors These integer values are used to identify the files for I/O operations The file descriptor 0 is reserved for standard input, the file descriptor 1 for standard output, and the file descriptor 2 for the standard error

File Descriptors ... continued

File Descriptors ... continued The POSIX standard defines the following File descriptor: A per-process, unique, nonnegative integer used to identify an open file for the purposes of file access Open file description: A record of how a process or group of processes are currently accessing a file Each file descriptor refers to exactly one open file description, but an open file description may be referred to by more than one file descriptor A file offset, file status, and file access modes are attributes of an open file description File access modes: Specification of whether the file can be read and written

File Descriptors ... continued File offset: The byte position in the file where the next I/O operation through that open file description begins Each open file description associated with a regular file, block special file, or directory has a file offset There is no file offset specified for a pipe or FIFO (described later) File status: Includes the following information append mode or not blocking/nonblocking Etc

File Descriptors ... continued FIFO special file: A type of file with the property that data written to such a file is read on a first-in-first-out basis Pipe: An object accessed by one of the pair of file descriptors created by the pipe() function Once created, the file descriptors can be used to manipulate the pipe, and it behaves identically to a FIFO special file when accessed this way It has no name in the file hierarchy

File Descriptors ... continued Important points A file descriptor does not describe a file It is just a number that is ephemerally associated with a particular open file description An open file description describes a past "open" operation on a file; its does not describe the file The description of the file is in the inode There may be several different open file descriptors (or none) referring at it any given time

Unix API Programming Examples and Techniques Examples with direct IO open, close, fdopen, lseek, unlink Variable argument list Note: Use man pages to get information on system calls Look into the system header files /usr/include/sys/types.h)

Direct I/O Using open() The usual C-language stream-oriented I/O operations, like printf(), use buffers and process data character-by-character They are implemented using the lower-level direct I/O operations read() and write() In situations where we do not want to view the data as characters, where we want greater efficiency, or where the extra (stream) layer of buffering causes us problems with synchronization, it is better to use the direct I/O operations

Using man Look at the man page for open() If there is more than one page on a given name, man will give you the one that is first in the chapter order of the Unix manual. Shell commands are in Section 1, I/O and OS interface calls are in Section 2 and Section 3 respectively Specification of section number varies On Red Hat Linux, type man 2 open or man -S 2 open to see the page on open from Section 2 of the Unix manual On Solaris, you can type man -s 2 open

man page for open #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> Solaris 2.6 includes the following synopsis int open(const char *path, int oflag, /* mode_t mode */ ...); Red Hat Linux 6.2 int open(const char *pathname, int flags, mode_t mode); 1996 POSIX standard synopsis is as follows int open(const char *path, int oflag, ...); The latest official POSIX/Unix synopsis No <sys/types.h> What does the ... mean here? Will a compiler allow this in an actual program?

Variable Argument Lists The ... indicates a variable number of arguments Similar to that in printf() For more on variable argument lists, look at the file /usr/include/stdarg.h Functions with variable argument lists can be dangerous It is difficult to check types, and the use of a correct number of arguments

example1.c illustrates a common programming error Example Programs example1.c illustrates a common programming error Failure to provide the correct number of arguments to a vararg function example2.c illustrates opening a file