INF322 Operating Systems

Similar documents
Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Introduction to Linux

Introduction to Linux

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

INTRODUCTION TO LINUX

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

CS Fundamentals of Programming II Fall Very Basic UNIX

Introduction to Linux

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

TEL2821/IS2150: INTRODUCTION TO SECURITY Lab: Operating Systems and Access Control

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Chapter-3. Introduction to Unix: Fundamental Commands

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Introduction to Unix: Fundamental Commands

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Linux/Cygwin Practice Computer Architecture

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

Introduction to Linux

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Linux at the Command Line Don Johnson of BU IS&T

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

CS 300 Data Structures

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

Perl and R Scripting for Biologists

Introduction to Linux

Working with Basic Linux. Daniel Balagué

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

CS246 Spring14 Programming Paradigm Notes on Linux

Introduction to Linux. Fundamentals of Computer Science

CS 300. Data Structures

5/8/2012. Creating and Changing Directories Chapter 7

EE516: Embedded Software Project 1. Setting Up Environment for Projects

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

Lec 1 add-on: Linux Intro

Introduction to the UNIX command line

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

UNIX File Hierarchy: Structure and Commands

Embedded System Design

1 Installation (briefly)

Overview of the UNIX File System

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

Everything about Linux User- and Filemanagement

Introduction to Supercomputing

Exercise 1: Basic Tools

CS/CIS 249 SP18 - Intro to Information Security

Linux Systems Administration Getting Started with Linux

CSCI 2132 Software Development. Lecture 4: Files and Directories

Outline. Structure of a UNIX command

Introduction. Let s start with the first set of slides

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Introduction: What is Unix?

Unix Introduction to UNIX

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

Filesystem and common commands

CISC 220 fall 2011, set 1: Linux basics

CS Unix Tools. Lecture 2 Fall Hussam Abu-Libdeh based on slides by David Slater. September 10, 2010

Unix System Architecture, File System, and Shell Commands

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

Introduction to Linux

Filesystem Hierarchy Operating systems I800 Edmund Laugasson

EECS2301. Lab 1 Winter 2016

CS197U: A Hands on Introduction to Unix

CENG393 Computer Networks Labwork 1

The Unix Shell & Shell Scripts

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Getting started with Hugs on Linux

Introduction to Linux

5/20/2007. Touring Essential Programs

TEL2821/IS2150: INTRODUCTION TO SECURITY Lab: Operating Systems and Access Control

CS4350 Unix Programming. Outline

CSC 112 Lab 1: Introduction to Unix and C++ Fall 2009

Introduction of Linux

CSC209. Software Tools and Systems Programming.

Commands are in black

Linux. An introduction. Aurélien Villani 01/2018

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Linux for Beginners. Windows users should download putty or bitvise:

Lab Working with Linux Command Line

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Practical Session 0 Introduction to Linux

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Std: XI CHAPTER-3 LINUX

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Operating Systems, Unix Files and Commands SEEM

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

Files

Computer Systems and Architecture

GNU/Linux Course Lesson 1. Puria Nafisi

System Programming. Introduction to Unix

Introduction to Cygwin Operating Environment

Introduction to Linux Basics

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Overview of the UNIX File System. Navigating and Viewing Directories

Introduction to Linux

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

Transcription:

Galatasaray University Computer Engineering Department INF322 Operating Systems TP01: Introduction to Linux Ozan Çağlayan ocaglayan@gsu.edu.tr ozancaglayan.com

Fundamental Concepts Definition of Operating System This is the definition that concerns us in this lab A central software managing a computer's resources + Accompanying softwares like command-line interpreters, GUIs, editors, browsers, etc. Central software that manages and allocates computer resources like CPU, RAM, devices, etc.

Fundamental Concepts Definition of Operating System Central software that manages and allocates computer resources like CPU, RAM, devices, etc. Kernel

Fundamental Concepts Definition of Operating System Central software that manages and allocates computer resources like CPU, RAM, devices, etc. Kernel [noun] the inner and usually edible part of a seed or grain or nut or fruit stone; "black walnut kernels are difficult to get out of the shell"

Kernel Provides a software layer to manage the limited resources of a computer, Process Management, User space Memory Management, Device Access, Networking, System Call Interface,... Kernel Space

Directory Layout

Single Directory Hierarchy Linux maintains a single hierarchical directory structure to organize all files in the system, This contrasts with Windows where each storage has its own directory hierarchy: C:\ for the 1 st disk partition D:\ for the 2 nd disk partition E:\ for DVD-ROM...

Single Directory Hierarchy / Root (/) directory bin run etc home usr firefox media group passwd ozan bob include TP1.pdf stdio.h Regular File Directory

Pathnames A pathname is a string consisting of an optional initial slash (/) followed by a series of filenames separated by slashes: /home/ozan/documents/tp1.pdf Path separator Filename

Pathnames An absolute pathname begins with a (/) and specifies the location of a file with respect to the root directory: /home/ozan/documents/tp1.pdf

Pathnames An absolute pathname begins with a (/) and specifies the location of a file with respect to the root directory: /home/ozan/documents/tp1.pdf A relative pathname specifies the location of a file with respect to the current working directory: Documents/TP1.pdf (When the current directory is /home/ozan)

Single Directory Hierarchy /bin: Essential commands /dev: Devices /home: User's home directories /etc: System-wide configuration files /root: Home directory for root user /var: Variable files like logs.

Home Directories Every user in the system has an associated home directory: C:\Users\ozan for Win Vista & 7 C:\Documents and Settings\ozan for Win XP /home/ozan under Linux Separating user data from system-wide data is always a good thing.

Home Directories What you will find in a typical home directory: [ozan@dellfedora ~]$ ls CyberClient.conf Downloads git Pictures svn Desktop Dropbox Music Public Templates Documents fontconfig OctaveToolboxes Setups Videos A typical user should only use its home directory for everything!

Users and Groups Each user is uniquely identified, and users may belong to groups, Every user has: A numeric ID called User ID (UID), A login name (username), A home directory under /home/username, A password, etc.

Superuser One special user known as superuser has special privileges in the system, User ID == 0 Login name (username) == root Superuser has access to everything, can install new software, can remove any directories, etc. Home directory for superuser is /root.

Superuser One special user known as superuser has special privileges in the system, User ID == 0 Login name (username) == root Superuser has access to everything, can install new software, can remove any directories, etc. Home directory for superuser is /root.

Permissions Each file has an associated User ID (UID) and Group ID (GID) which define the owner of the file and the group to which it belongs, Every user has full read/write access to all files and directories in their /home directory, Superuser has all access to everything!

Permissions Every user in the system is isolated from the rest in terms of their home directories, User Bob cannot touch anything within: /home/ozan /home/anna /home/ahmet...

Mounting Other Storage Devices

Single Directory Hierarchy / Root (/) directory bin run etc home usr If there is a single directory hierarchy, where are all other disks, USB sticks, DVDs, CDs? firefox media group passwd ozan bob include TP1.pdf stdio.h Regular File Directory

Single Directory Hierarchy / Root (/) directory bin run etc media firefox group passwd

Single Directory Hierarchy User ozan plugged a USB stick / Root (/) directory bin run etc media firefox group passwd

Single Directory Hierarchy / Root (/) directory bin run etc media firefox group passwd User name ozan Disk label OZAN guide.pdf boardingpass_1360935081443.pdf

Single Directory Hierarchy / Root (/) directory bin run etc media firefox group passwd User name Disk label ozan OZAN Every storage becomes a Sub-tree of this hierarchy! guide.pdf boardingpass_1360935081443.pdf

Single Directory Hierarchy / Root (/) directory bin run etc media firefox group passwd User name ozan Disk label OZAN guide.pdf boardingpass_1360935081443.pdf

Single Directory Hierarchy All other storage devices are tied/mounted into this single directory hierarchy, This is done automatically by the system.

Interacting With The System

? Question: How come people interacted with computers at times when graphic cards were not invented?

Terminals Question: How come people interacted with computers at times when graphic cards were not invented? Answer: Using primitive terminals connected through serial port (RS-232).

Terminals (TeleTYpewriters, TTY) Output using printer Input using punch cards

Terminals (Early Video Type) Still connected through RS-232 port, Designed using microprocessors.

Terminals (Today) As many terminals as tabs in a terminal emulator, Each one runs its own shell.

Shell Special-purpose program to read commands typed by a user and execute programs in response to that commands. Kernel

Shell Special-purpose program to read commands typed by a user and execute programs in response to that commands. Shell Kernel

Shell Special-purpose program to read commands typed by a user and execute programs in response to that commands. Shell is just a program which waits for your input in a loop, Different shells available: sh, bash, csh, tcsh, zsh, etc.

Practice Press ALT+F2 and type gnome-terminal to launch a terminal emulator, Now you have a shell prompt at your order: [ozan@dellfedora ~]$ whoami ozan [ozan@dellfedora ~]$ date Prş Şub 21 13:27:56 EET 2013 [ozan@dellfedora ~]$ echo "GSU" GSU

Environment Variables Each process has an array of strings in key=value form called Environment List, A common use of environment variables is in the shell. Shell holds a list of these variables for various things, Now type printenv to see a list of these environment variables.

Environment Variables [ozan@dellfedora ~]$ printenv... SHELL=/bin/bash USER=ozan PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin HOME=/home/ozan......

Environment Variables [ozan@dellfedora ~]$ printenv... SHELL=/bin/bash USER=ozan PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin HOME=/home/ozan...... [ozan@dellfedora ~]$ echo $USER ozan [ozan@dellfedora ~]$ echo USER USER You have to put '$' before the variable so that the shell interprets is as a variable instead of a plain string!

Exercice: Let's write whoami! You've seen that shell has an environment variable called $USER,

Exercice: Let's write whoami! You've seen that shell has an environment variable called $USER, Standard C library provides: char *getenv(const char *name) Use man utility to see documentation about practically anything if a documentation exists and is installed: [ozan@dellfedora ~]$ man getenv

Exercice: Let's write whoami! GETENV(3) Linux Programmer's Manual NAME getenv, secure_getenv - get an environment variable SYNOPSIS #include <stdlib.h> char *getenv(const char *name); DESCRIPTION The getenv() function searches the environment list to find the environment variable name, and returns a pointer to the corresponding value string. RETURN VALUE The getenv() function returns a pointer to the value in the environment or NULL if there is no match.

Exercice: Let's write whoami! Type gedit and press Enter to launch a simple text editor, Final source code is ~12 lines and looks something like this:

Exercice: Let's write whoami! Type gedit and press Enter to launch a simple text editor, Final source code is ~12 lines and looks something like this:

Exercice: Let's write whoami! Now, how to compile it? We use gcc (GNU project C and C++ compiler) to compile it: gcc whoami.c -o whoami List of.c sources Name of the output executable When -o is not given, the resulting executable is called a.out

Exercice: Let's write whoami! Now, how to compile it? Done. How to run it?

Exercice: Let's write whoami! Now, how to compile it? Done. How to run it? Type whoami and press Enter: [ozan@dellfedora ~]$ whoami ozan

Exercice: Let's write whoami! Now, how to compile it? Done. How to run it? Type whoami and press Enter: [ozan@dellfedora ~]$ whoami ozan Really?

Exercice: Let's write whoami! Now, how to compile it? Done. How to run it? Type whoami and press Enter: [ozan@dellfedora ~]$ whoami ozan Really? But how does it differ from the system provided whoami?

Steps of program execution When you type whoami and press Enter, shell executes the whoami program and whoami prints your username. Questions Where is whoami? How is it located by the shell?

Steps of program execution whoami utility comes from a package called coreutils: http://www.gnu.org/software/coreutils/ coreutils also provides cat, chmod, chown, ls, cp, dd, df, du, head, mkdir, mv, printenv, rm, etc. practically every basic tool that we daily use on a Linux system.

Steps of program execution coreutils is installed in every Linux distribution be it Fedora, Ubuntu or OpenSuSE, etc. The installation directory may differ for each distribution but usually you will find whoami under /usr/bin, [ozan@dellfedora OS-Course]$ ls -lh /usr/bin/whoami -rwxr-xr-x 1 root root 32K Oca 24 18:43 /usr/bin/whoami Permissions Ownership Modification Time Filename

Steps of program execution Shell looks in the environment variable $PATH and adds whoami at the end of each path to see if the resulting path actually exists: /usr/local/bin /usr/bin $PATH /bin /usr/local/sbin /usr/sbin

Steps of program execution Shell looks in the environment variable $PATH and adds whoami at the end of each path to see if the resulting path actually exists: $PATH /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin Does /usr/local/bin/whoami exist? No, continue

Steps of program execution Shell looks in the environment variable $PATH and adds whoami at the end of each path to see if the resulting path actually exists: $PATH /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin Does /usr/bin/whoami exist? Yes, execute it!

Back to whoami Now, how to compile it? Done. How to run it? Type whoami and press Enter: [ozan@dellfedora ~]$ whoami ozan Really?

Back to whoami Now, how to compile it? Done. How to run it? Type whoami and press Enter: [ozan@dellfedora ~]$ whoami ozan Really? No. Shell will run the system-provided whoami found under /usr/bin.

Back to whoami Now, how to compile it? Done. How to run it? You have to explicitly tell your shell to run the whoami found in the current directory:

Back to whoami Now, how to compile it? Done. How to run it? You have to explicitly tell your shell to run the whoami found in the current directory: [ozan@dellfedora ~]$./whoami ozan '.' (dot) specifies current directory, '..' specifies upper directory, '/' is path separator.

Finally... That's not how the real whoami utility is implemented, Run the following command: USER= bill./whoami What happened and why? Discuss.

Galatasaray University Computer Engineering Department Any questions? Reference book The Linux Programming Interface Michael Kerrisk Ozan Çağlayan ocaglayan@gsu.edu.tr ozancaglayan.com