Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 5 Acknowledgements: The syllabus and power point presentations are modified versions.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Chapter 3 Process Description and Control
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
COSC 120 Computer Programming
Chapter 10.
The ‘system-call’ ID-numbers How can Linux applications written in assembly language create and access files?
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Linux+ Guide to Linux Certification, Second Edition
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
Introduction to Kernel
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Linux+ Guide to Linux Certification, Second Edition
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
1 File Management Chapter File Management File management system consists of system utility programs that run as privileged applications Input to.
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.
Guide To UNIX Using Linux Third Edition
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
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.
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.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
Introduction to Computer Programming Using C Session 23 - Review.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
Linux+ Guide to Linux Certification, Third Edition
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
Chapter 2: Linux & POSIX “She sells bash shells by the C shore”
Operating Systems COMP 4850/CISG 5550 File Systems Files Dr. James Money.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
1 File Management Chapter File Management n File management system consists of system utility programs that run as privileged applications n Concerned.
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
System calls for Process management
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
CE Operating Systems Lecture 17 File systems – interface and implementation.
Operating Systems Process Creation
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
Introduction to Programming Using C An Introduction to Operating Systems.
Advanced Programming in the UNIX Environment Hop Lee.
UNIX & Windows NT Name: Jing Bai ID: Date:8/28/00.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 9 Acknowledgements: The syllabus and power point presentations are modified versions.
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
System calls for Process management Process creation, termination, waiting.
Learners Support Publications Working with Files.
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
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.
系統程式 System Programming 羅習五 國立中正大學資訊工程學系 Class: EA-001 (05) ext.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Introduction to Kernel
Advanced UNIX progamming
An overview of the kernel structure
Topics Introduction to File Input and Output
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 progamming
Topics Introduction to File Input and Output
The UNIX Time Sharing System
Presentation transcript:

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

Announcements Reading assignment –APUE Chapter 1 –APUE Chapter 3 Pages 47-56, –APUE Chapter 4 Pages 77-81, –APUE Chapter 5

Review Review some features of C –Header files –Command line arguments –Utilities Review some UNIX system calls –system, etc Portability –Standards: ANSI, POSIX, etc – 32 bit vs 64 bit –Byte order: Little endian vs big endian

Week 2 Topics Review some features of CReview some features of C –Header files –Command line arguments –Utilities Review some UNIX system callsReview some UNIX system calls –system, etc PortabilityPortability –Standards: ANSI, POSIX, etc – 32 bit vs 64 bit –Byte order: Little endian vs big endian

Week 2 Topics... continued Introduction to the UNIX APIIntroduction to the UNIX API –Environment variables –Exit status –Process ID –User ID UNIX file systemUNIX file system –File system abstraction –Directories –File descriptors

Review some features of C Header files Macros Command line argumentsCommand line arguments –See example1.c Utilities

Some Unix System Calls You may use these in your first assignment –system –mkstemp –See example2.c

system #include int system(const char *string); –Works as if string is typed into the shell at a terminal –Returns the exit status (see man page for waitpid) –Usually -1 is returned if there is an error

mkstemp #include int mkstemp(char *template) –template should end in XXXXXX –It replaces XXXXXX with unique file name, and returns an open file descriptor for a file available for reading and writing

Portability Standards –Source code portability: ANSI/ISO C –UNIX standards: POSIX, open group –Internet engineering task force (IETF) 32 bit vs 64 bit Byte order – Little endian vs big endian

Source Code Portability Standard programming language –Example: ANSI/ISO C ISO C90 is in use; C99 is latest - should it be used? Standard libraries Standard API to operating system –Example: POSIX.1 Auto-configuration mechanisms Programmer discipline

Unix Standards POSIX (IEEE STDS 1003.x and ISO/IEC 9945) –POSIX.1: System API for C language –POSIX.2: Shell and utilities –POSIX.5: System API for Ada language –POSIX.9: System API for Fortran language See also and

Unix Standards... continued The Open Group –A consortium of vendors and user organizations –Consolidation of X/Open and the Open Software Foundation –Controls the UNIX trademark –The Austin Group combined the IEEE, TOG, and ISO standardsAustin Group See also and 975http://

IETF Internet Engineering Task Force (IETF) –Network designers, operators, vendors, researchers –Deals with the Internet –Issues RFCs See also

64-bit vs. 32-bit architecture Pointers cannot be stored as int size_t cannot be stored as int long may not be long enough for size_t and off_t DatatypeILP32LP64 char88 short16 int32 long3264 pointer3264 ( long long )64 Note: ILP32 and LP64 are not the only two models

Byte order Little-Endian – Low-order byte is stored at lowest address Big-Endian – High-order byte is stored at lowest address

Introduction to the UNIX API Environment variables Exit status Process ID User ID

Environment Variables Associated with each process is a set of environment variables, each having a value –These values are passed to the process when it is executed –Along with argc and argv, this is another way of passing parameters to a program –Example: when in the Bourne shell you execute export DISPLAY=mysystem:0.0 The environment variable DISPLAY has value mysystem:0.0 –A process can access its environment variables using either (i) external variable environ, or (ii) function getenv() See example3.c

Exit status Each process (except the system's initial process) has a parent process –When a process terminates, its parent can find out what caused the termination, via a status value The termination status contains a short integer exit status code The function exit() allows a process to terminate itself and specify the exit status code that it wants to return to the parent –When a command is run from a shell, the exit status code is returned to the shell, which allows it to be used in job control statements –What is the difference between _exit() and exit()?

Process ID Each process has a unique identifier, of signed arithmetic type pid_t The process ID of the current process can be obtained by calling the function getpid()

User ID Associated with each process are two user ID's –A fixed real user ID, and –A changeable effective user ID In order to modify privileges – The real user ID can be obtained by calling getuid() –See example4.c

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 exit 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

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 A character special file that does not refer to a terminal device may have 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