CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 6: Unix Systems Overview.

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

Operating System Structures
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Concepts about the file system 2. The disk structure 3. Files in disk – The ext2 FS 4. The Virtual File System (c) 2013, Prof. Jordi Garcia.
Basic Unix system administration
Linux can be generally divided into four major components: 1. KERNEL – OS, ultimate boss The kernel is the core program that runs programs and manages.
File Systems.
1 UNIX 1 History of UNIX 2 Overview of UNIX 3 Processes in UNIX 4 Memory management in UNIX 5 The UNIX file system 6 Input/output in UNIX.
Operating Systems File Systems (in a Day) Ch
Phones OFF Please Operating System Introduction Parminder Singh Kang Home:
Network+ Guide to Networks, Fourth Edition
Ceng Operating Systems
Operating Systems - Introduction S H Srinivasan
Operating Systems File Systems (Select parts of Ch 6)
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
1 Friday, July 07, 2006 “Vision without action is a daydream, Action without a vision is a nightmare.” - Japanese Proverb.
Silberschatz, Galvin and Gagne  Operating System Concepts Common OS Components Process Management Memory Management File Management I/O System.
CMPE 151: Network Administration Spring Class Description Focus: system and network administration. Sequence of exercises. E.g., installing/configuring.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Introduction to Linux/UNIX. History UNIX beginnings in 1969 (Linus Torvalds is born!) AT & T Bell Laboratories (Ken Thompson & Dennis Richie) Working.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 3: Unix Systems Overview.
Introduction A computer system consists of hardware system programs application programs.
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
CS240 Computer Science II Introduction to Unix Based on “UNIX for Programmers and Users” by G.Class and K. Ables.
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.
CIS 191 – Lesson 2 System Administration. CIS 191 – Lesson 2 System Architecture Component Architecture –The OS provides the simple components from which.
Unix Basics Chapter 4.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
CS 390 Unix Programming Summer Unix Programming - CS 3902 Course Details Online Information Please check.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
File Systems Security File Systems Implementation.
CS2204: Introduction to Unix January 19 th, 2004 Class Meeting 1 * Notes adapted by Christian Allgood from previous work by other members of the CS faculty.
Introduction to Programming Using C An Introduction to Operating Systems.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Slide: 1 UNIX FILE SYSTEM By:Qing Yang ID: Operating System Research Topic December, 2000.
UNIX & Windows NT Name: Jing Bai ID: Date:8/28/00.
Basic UNIX Concepts. Why We Need an Operating System (OS) OS interacts with hardware and manages programs. A safe environment for programs to run is required.
Linux File system and VFS. A simple description of the UNIX system, also applicable to Linux, is this: "On a UNIX system, everything is a file; if something.
THE FILE SYSTEM Files long-term storage RAM short-term storage Programs, data, and text are all stored in files, which is stored on.
Introduction to UNIX CS 2204 Class meeting 1 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Lecture 19 Linux/Unix – File System
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Review CS File Systems - Partitions What is a hard disk partition?
MINIX Presented by: Clinton Morse, Joseph Paetz, Theresa Sullivan, and Angela Volk.
WHY AN OPERATING SYSTEM (OS) OS interacts with hardware and manages programs. Programs not expected to know which hardware they will run on. Must be possible.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Operating Systems.
Overview of Linux Fall 2016 Dr. Donghyun Kim
UNIX Introduction History Main Features UNIX Operating System
Chapter 2: System Structures
The Linux Operating System
Filesystems.
An overview of the kernel structure
Unix : Introduction and Commands
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Operating Systems Lecture 4.
Chapter 7 File and file System structure
Introduction to Linux/UNIX
UNIX Introduction.
Chapter 1: Introduction CSS503 Systems Programming
Lecture 26: File Systems CS April 29, 2019.
Introduction to Operating Systems
The UNIX Time Sharing System
Presentation transcript:

CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 6: Unix Systems Overview

What is an Operating System An Operating System (OS) is a layer of software that sits in between the hardware and the user programs. Resource sharing: OS as Referee Sharing among processes, users, etc resource allocation, allocate processors, memory, network bandwidth, disk space, etc. Isolation: error in one application should not disrupt another Communication:

What is an Operating System Masking Limitations: OS as Illusionist Virtualization: provide an application with the illusion of resources that are not physically present E.g., illusion of dedicated processor, memory over whole address space Provides a convenient and flexible programming environment than the underlying hardware

What is an Operating System Providing Common Services: OS as Glue Provide a set of common, standard services to applications to simplify and standardize their design File system hides details of storage Network socket abstraction hides details of network communication GUI, devices, sensors, etc.

What is an Operating System Window System – Graphical use interface Standard Programs – Programs such as a web browser, task manager, editors, compilers etc. Common Libraries – Libraries common to all programs running in the computer such as math library, string library, window library, c library etc. It has to do all of the above in a secure and reliable manner.

A Tour of UNIX We will start by describing the UNIX operating system (OS). Understanding one instance of an Operating System will help us understand other OSs such as Windows, Mac OS, Linux etc. UNIX is an operating system created in 1969 by Ken Thompson, Dennis Ritchie, Brian Kernighan, and others at AT&T Bell Labs. UNIX was a successor of another OS called MULTICS that was more innovative but it had many problems. UNIX was smaller, faster, and more reliable than MULTICS.

A Tour of UNIX UNIX was initially created to support typesetting (edition of documents). By having the programmers being the users themselves of the OS (eat your own food), UNIX became the robust, practical system that we know today. UNIX was written in “C” (95%) and assembly language (5%). This allowed UNIX to be ported to other machines besides Digital Equipment (DEC)’s PDP11.

BSD UNIX UNIX was a success in the universities. Universities wanted to modify the UNIX sources for experimentation do Berkeley created its own version of UNIX called BSD- UNIX. POSIX is an organization that created the POSIX UNIX standard to unify the different flavors of UNIX. Sockets, FTP, Mail etc came from BSD UNIX.

Linux GNU Project (1984, Richard Stallman) Create “free” UNIX implementation Produced GNU C compilers, and other programs Lacks a kernel Linux (1991, Linus Torvalds, kernel on 386) Inspired by Minix Other developers quickly joined

The UNIX File System

UNIX File System UNIX has a hierarchical File System Important directories / - Root Directory /etc OS Configuration files /etc/passwd – User information /etc/groups – Group information /etc/inetd.conf – Configuration of Internet Services (deamons) /etc/rc.*/ - OS initialization scripts for different services. Daemons – Programs running in the background implementing a service. (Servers).

UNIX File System /dev – List of devices attached to the computer /usr – Libraries and tools /usr/bin – Application programs such as grep, ls et /usr/lib – Libraries used by the application programs /usr/include – Include files (.h) for the libraries /home – Home directories

Users UNIX was designed as a multiuser system. The database of users is in /etc/passwd lore 66 $ cat /etc/passwd | grep ninghui ninghui:x:116:116:Ninghui Li,,,:/homes/ninghui:/usr/local/bin/bash Each line has the format: login_name:x:userid:groupid:Name,,,:homedir:shell x indicates that the hashed password is stored elsewhere (/etc/shadow) userid: Every user has a different “USER ID” that is a number that identifies the user uniquely in the system. User ID 0 means root user

Users ninghui:x:116:116:Ninghui Li,,,:/homes/ninghui:/usr/local/bin/bash login_name:x:userid:groupid:Name,,,:homedir:shell :groupid: :Name,,,: Full name and optionally other info :homedir: Home directory of the user. The directory where the user’s files are under :shell: The login shell.

Users Commands for users adduser – Adds a new user passwd – Change password. There exist a special user called “root” with special privileges. Only root can modify files anywhere in the system. To login as root (superuser) use the command “su”. Only root can add users or reset passwords.

Groups A “group” represents a group of users. A user can belong to several groups. The file /etc/group describes the different groups in the system.

Yellow Pages In some systems the password and group files is stored in a server called “Yellow Pages” that makes the management easier. If your UNIX system uses yellow pages the group and database are in a server. Use “ypcat” ypcat group | grep cs252 cs252:*:10174:cs252,grr,kompella,ninghui,cao82,goswama,joshi c,mminaeib,su17,wday,ehanau,jennen Also the passwd file can be in Yellow Pages: lore 16 % ypcat passwd | grep grr grr:##grr:759:759:Gustavo Rodriguez-Rivera,,,:/homes/grr:/bin/tcsh

File Systems The storage can be classified from fastest to slowest in the following Registers Cache RAM Flash Memory Disk CD/DVD Tape Network storage

Disk File Systems The disk is an electromagnetic and mechanical device that is used to store information permanently. The disk is divided into sectors, tracks and blocks

Disk File Systems Sector Track

Disk File Systems Block A Block is the intersection between a sector and a track

Disk File Systems Disks when formatted are divided into sectors, tracks and blocks. Disks are logically divided into partitions. A partition is a group of blocks. Each partition is a different file system.

Disk File System Partition 1Partition 2Partition 3 Inode ListData Blocks Boot Block Super Block

Disk File System Each partition is divided into: Boot Block – Has a piece of code that jumps to the OS for loading. Superblock – Contain information about the number of data blocks in the partition, number of inodes, bitmap for used/free inodes, and bitmap for used/free blocks, the inode for the root directory and other partition information. Inode-list – It is a list of I-nodes. An inode has information about a file and what blocks make the file. There is one inode for each file in the disk. Data Blocks – Store the file data.

I-node information An i-node represents a file in disk. Each i-node contains: 1. Flag/Mode 1. Read, Write, Execute (for Owner/Group/All) RWX RWX RWX 2. Owners 1. Userid, Groupid 3. Time Stamps 1. Creation time, Access Time, Modification Time. 4. Size 1. Size of file in bytes 5. Ref. Count – 1. Reference count with the number of times the i-node appears in a directory (hard links). 2. Increases every time file is added to a directory. The file the i-node represents will be removed when the reference count reaches 0.

I-node information The I-node also contains a block index with the blocks that form the file. To save space, the block index uses indices of different levels. This benefits small files since they form the largest percentage of files. Small files only uses the direct and single-indirect blocks. This saves in space spent in block indices.

I-node information Direct block – Points directly to the block. There are 12 of them in the structure Single indirect – Points to a block table that has 256 entry's. There are 3 of them. Double indirect – Points to a page table of 256 entries which then points to another page table of 256 Triple Indirect Points to a page table of 256 entries which then points to another page table of 256 that points to another page of 256 bytes.

I-node Block Index … 12 direct blocks 3 single indirect blocks 1 double indirect 1 triple indirect … I-node

I-node information Assume 1KB block and 256 block numbers in each index block. Direct block = 12 * 1Kb = 12Kb Single indirect = 3 * 256 * 1Kb = 768 Kb Double indirect = 1 * 256 * 256 * 1Kb = 64 Mb Triple indirect = 1 * 256 * 256 * 256 * 1Kb = 16 Gb

I-node information Most of the files in a system are small. This also saves disk access time since small files need only direct blocks. 1 disk access for the I-Node 1 disk access for the datablock. An alternative to the multi-level block index is a linked list. Every block will contain a pointer to the next block and so on. Linked lists are slow for random access.

UNIX Processes

Process’ Properties A process has the following properties: PID: Index in process table Command and Arguments Environment Variables Current Dir Owner (User ID) Stdin/Stdout/Stderr Use ps or top to see process information

Process ID Uniquely identifies the processes among all live processes. The initial process (init process) has ID of 0. The OS assigns the numbers in ascending order. The numbers wrap around when they reach the maximum and then are reused as long as there is no live process with the same processID. You can programmatically get the process id with int getpid();

Command and Arguments Every process also has a command that is executing (the program file or script) and 0 or more arguments. The arguments are passed to main. int main(int argc, char **argv); argc contains the number of arguments including the command name. argv[0] contains the name of the command

Printing the Arguments printargs.c: int main(int argc, char **argv) { int i; for (i=0; i<argc; i++) { printf(“argv[%d]=\”%s\”\n”, i, argv[i]); } gcc –o printargs printargs.c./printargs hello world argv[0]=“./printargs” argv[1]=“hello” argv[2]=“world”

Environment Variables It is an array of strings of the form A=B that is inherited from the parent process. Some important variables are: PATH=/bin:/usr/bin:. Stores the list of directories that contain commands to execute. USER= Contains the name of the user HOME=/homes/grr Contains the home directory. You can add Environment variables settings in.login or.bashrc and they will be set when starting a shell session.

Environment Variables To set a variable from a shell use export A=B Example: Add a new directory to PATH export PATH=$PATH:/newdir

Printing Environment To print environment from a shell type “env”. lore 24 % env USER=grr LOGNAME=grr HOME=/homes/grr PATH=/opt/csw/bin:/opt/csw/gcc3/bin:/p/egcs- 1.1b/bin:/u/u238/grr/Orbix/bin:/usr/local/gnu:/p/srg/bin :/usr/ccs/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:/usr /hosts:/usr/local/X11:/usr/local/gnu:. MAIL=/var/mail/grr SHELL=/bin/tcsh TZ=US/East-Indiana …

Printing Environment from a Program Can access environment variables through the “char ** environ” variable in C. environ points to an array of strings of the form A=B and ends with a NULL entry. extern char **environ; int main(int argc, char **argv) { int i=0; while (environ[i]!=NULL) { printf(“%s\n”,environ[i]); i++; }

Current Directory Every process also has a current directory. The open file operations such as open() and fopen() will use the current directory to resolve relative paths. If the path does not start with “/” then a path is relative to the current directory. /etc/hello.c – Absolute path hello.c – Relative path. To change the directory use “cd dir” in a shell or chdir(dir) inside a program

Stdin/Stdout/Stderr/Redirection Also a process inherits from the parent a stdin/stdout and stderr. They are usually the keyboard and the terminal but they can be redirected. Example: command < in.txt // redirect stdin > out.txt // redirect stdout 2> err.txt // redirect stderr

Redirection of stdin/stdout/stderr command >> out Append output of the command into out. command > out.txt 2> err.txt Redirect stdout and stderr. command > out.txt 2>&1 Redirect both stderr and stdout to file out.txt

PIPES In UNIX you can connect the output of a command to the input of another using PIPES. Example: ls –al | sort Lists the files in sorted order.

Review Understand the effect of redirecting and using pipes. Understand the 3-layered arrangement for identifying which disk blocks are used for a file.