CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten.

Slides:



Advertisements
Similar presentations
File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
Advertisements

Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
January 13, Csci 2111: Data and File Structures Week1, Lecture 2 Basic File Processing Operations.
Chapter 11: Data Files & File Processing In this chapter, you will learn about Files and streams Creating a sequential access file Reading data from a.
FILES Files types and operations. Files Files are used to store data Data can be Text (ASCII only: 0  127) Binary (Full range: 0  256) Each file resides.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
 2000 Prentice Hall, Inc. All rights reserved. Chapter 11 – File Processing Outline 11.1Introduction 11.2The Data Hierarchy 11.3Files and Streams 11.4Creating.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CS 311 – Lecture 09 Outline Introduction to Systems programming – System calls – Categories of system calls Error Management System calls File Handling.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
Lone Leth Thomsen Input / Output and Files. April 2006Basis-C-8/LL2 sprintf() and sscanf() The functions sprintf() and sscanf() are string versions of.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 7P. 1Winter Quarter File I/O in C Lecture.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Introduction to Programming Using C Files. 2 Contents Files Working with files Sequential files Records.
File IO and command line input CSE 2451 Rong Shi.
Chapter 8 File-Oriented Input and Output. 8.1 INTRODUCTION a file can also be designed to store data. We can easily update files, A data file as input.
CSEB114: Principle of programming Chapter 11: Data Files & File Processing.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Week 12 - Wednesday.  What did we talk about last time?  File I/O  Binary trees  Lab 11.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
Lecture 8a: File I/O BJ Furman 21MAR2011. Learning Objectives Explain what is meant by a data stream Explain the concept of a ‘file’ Open and close files.
1 IT 252 Computer Organization and Architecture Interaction Between Systems: File Sharing R. Helps.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
 2000 Prentice Hall, Inc. All rights reserved Introduction Data files –Can be created, updated, and processed by C programs –Are used for permanent.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 11 – File Processing Outline 11.1Introduction.
Chapter 12 Files (reference: Deitel ’ s chap 11) chap8.
Chapter 7 : File Processing1 File-Oriented Input & Output CHAPTER 7.
1 CHAPTER6 CHAPTER 6. Objectives: You’ll learn about;  Introduction  Files and streams  Creating a sequential access file  Reading data from a sequential.
Lecture 11: Files & Arrays B Burlingame 18 November 2015.
Chapter 7 Files By C. Shing ITEC Dept Radford University.
CNG 140 C Programming (Lecture set 10) Spring Chapter 10 Data Files.
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
Files A collection of related data treated as a unit. Two types Text
 2007 Pearson Education, Inc. All rights reserved. 1 C File Processing.
Files. FILE * u In C, we use a FILE * data type to access files. u FILE * is defined in /usr/include/stdio.h u An example: #include int main() { FILE.
1 Computer Programming Lecture 15 Text File I/O Assist. Prof Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering
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.
Advanced Programming in the UNIX Environment Hop Lee.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
By C. Shing ITEC Dept Radford University
TMF1414 Introduction to Programming
File Access (7.5) CSE 2031 Fall July 2018.
File I/O.
Files I/O, Streams, I/O Redirection, Reading with fscanf
File I/O We are used to reading from and writing to the terminal:
Chapter 11 – File Processing
Manipulating File IO in Visual C++
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
CSE 333 – Section 3 POSIX I/O Functions.
File Structure Related system calls
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Text and Binary File Processing
File Input and Output.
File Access (7.5) CSE 2031 Fall January 2019.
Fundamental of Programming (C)
File Access (7.5) CSE 2031 Fall February 2019.
C Preprocessing File I/O
EPSII 59:006 Spring 2004.
FILE handeling.
Chapter 11 Files chap8.
Professor Jodi Neely-Ritz University of Florida
File I/O We are used to reading from and writing to the terminal:
Presentation transcript:

CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten

CSE /21/09 Performance Measuring Timing Program Activities Time Measurement Resolution Improving Accuracy Activity Types to Time

Measuring Time Offset Grab start time Run activity Grab end time Get difference

Grab Wallclock Time time(2) -- seconds since epoch gettimeofday(2) -- returns timeval structure –tv_sec -- seconds since epoch –tv_usec -- microseconds after last second times(2), clock(2) for user/system times

How? Look at the man pages Need header files –#include for time(2) –#include for gettimeofday(2) Other times are more complex

Resolution and Accuracy Resolution of timer clocks Variability in concurrent system activities Fast activities may be repeated many times, then get the averaged Longer activities may be repeated several times, then use the minimum

What do you time? Code algorithms File I/O delays Communications delays

UNIX Errors (1) system calls return null instead of a pointer, or -1 instead of an nonnegative integer errno(3) -- the error for that system call, it is NOT set if there is no error (retains any old errno value) strerror(3) -- the standard explanatory string for the errno.

UNIX Errors (2) #include to access errno #include to access strerror Note the possible errors for each system call as listed in the system call's man page!

Stream File Access fopen(3), freopen(3), fclose(3) fprintf(3), fscanf(3) (formatted string I/O) fgets(3), fputs(3), fgetc(3), fputc(3) All use pointers to FILE for the stream #include

fopen(), freopen() Parameters A string for the file path, absolute or relative to the current working directory A string of access mode characters –r, r+ –w, w+ –a, a+

Descriptor File Access open(2), creat(2), close(2) read(2), write(2) A file descriptor is an "int" #include

open() Parameters file path string open flags (OR'ed together) –O_CREAT, O_EXCL, O_TRUNC, O_APPEND mode -- combined with umask for new file permissions (mode & !umask)

Useful Calls fdopen(3) -- file descriptor to FILE pointer fileno(3) -- FILE pointer to its file descriptor feof(3) -- returns nonzero if eof was found fcntl(2) -- control behavior for file descriptor stat(2), fstat(2), and lstat(2)

More Useful Calls chmod(2) – change permissions on file chown(2) – change file ownership and group unlink(2) – delete a file mkdir(2), rmdir(2), chdir(2), getcwd(3)

Assignment MP2 (1) Write a C program to time how long it takes to fopen(), fgets() once, and fclose() 100 files, printing out the total time in seconds, and compute and print the average time in milliseconds. Then repeat using only the first (0) file, accessing it 100 times.

Assignment MP2 (2) Then access file "MP2_Problem", detecting all the possible errors for fopen(), fgets(), and fclose(), printing the error string and errno for any errors found, but continuing to the next operation even if the current operation fails. The files are all in "~jholten/cs222_files/"

Assignment MP2 (3) Include the UG and Journal. Include a single output file with the results of the three tests concatenated into the file. Include all source code.