...looking a bit closer under the hood

Slides:



Advertisements
Similar presentations
June 1, 1999Foreground/Background Processing1 Introduction to UNIX H. Foreground/Background Processing.
Advertisements

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
UNIX Process Processes Commands that deal with processes
Processes and Job Control. Foreground and Background (1)  Unix is a multi-tasking operating system –some of these tasks are being done by other users.
Essential System Administration 3rd Edition Chapter 2 The Unix Way(Cont.) University Of Palestine.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
1 Introduction to UNIX Ke Liu
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Exploring the UNIX File System and File Security
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Linux+ Guide to Linux Certification, Second Edition
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
Section 3.1: 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.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
Linux+ Guide to Linux Certification, Third Edition
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Chapter Two Exploring the UNIX File System and File Security.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 6 System Calls OS System.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
System calls for Process management
Linux+ Guide to Linux Certification, Third Edition
Operating Systems Process Creation
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.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
System calls for Process management Process creation, termination, waiting.
CSC414 “Introduction to UNIX/ Linux” Lecture 3
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
1 CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Implementation of a simple shell, xssh
SYSTEM ADMINISTRATION PART I by İlker Korkmaz and Kaya Oğuz
slides created by Marty Stepp, modified by Josh Goodwin
Implementation of a simple shell, xssh (Section 1 version)
...looking a bit closer under the hood
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Avani R.Vasant V.V.P. Engineering College
Implementation of a simple shell, xssh
Hands On UNIX AfNOG 2010 Kigali, Rwanda
Unix Process Management
Unix Systems Administration
CSE 374 Programming Concepts & Tools
Hands On UNIX AfNOG X Cairo, Egypt
Basic UNIX OLC Training.
Exploring the UNIX File System and File Security
Chapter 2: The Linux System Part 2
Unix : Introduction and Commands
...looking a bit closer under the hood
Chapter Four UNIX File Processing.
CHAPTER 13 Processes.
Introduction Paul Flynn
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Linux Filesystem Management
Lecture 6 Introduction to Process Management
Presentation transcript:

...looking a bit closer under the hood A UNIX tour ...looking a bit closer under the hood

Processes A running instance of a program is called a "process" Identified by a numeric process id (pid) unique while process is running; will be re-used some time after it terminates Has its own private memory space not accessible by other processes; not even other instances of the same program

What does UNIX give a process? A table of environment variables just a bunch of name=value settings kept in memory (process gets own private copy) A table of open files 0: standard input 1: standard output 2: standard error A set of argument strings e.g. what you put after the command name THAT'S ALL!!

The shell: a simple interface The shell lets you start processes and waits for them to finish, unless you run them in the "background" The shell lets you set environment variables The shell lets you set up file descriptors Normally stdin is connected to your keyboard and stdout/stderr to your screen, but you can override The shell lets you pass arguments

Shell expansion The shell performs processing on your command line before starting the program Splits line into words (cmd, arg1, arg2,...) Searches for cmd in PATH if required Performs various types of argument expansion See exercise

The shell itself runs as a process A shell can start another shell A shell has its own environment e.g. it uses the PATH setting to locate programs it copies the environment to its children A shell has stdin/stdout/stderr You can run a non-interactive shell, i.e. a script Examples include periodic system tidying log rotation rebuilding of the locate database rebuilding of the man page index

How are new processes started ? The current processes “clones” itself via the fork() call The fork'ed copy is called the child it shares all the characteristics of the parent, including memory, open files, etc... The child replaces itself by calling the new program to run via exec() | fork() / \ parent child | exec()

Once a process has started... It can make "system calls" to the Kernel as needed, e.g. to read and write data open and close files start new child processes (known as "fork") ...etc Using its pid, you can send it a "signal", e.g. Request to terminate Request to suspend (stop temporarily) or restart Certain system events also send signals When it ends, returns 'exit code' (0-127) to parent (the process which started it)

Process control from the shell For a "foreground" process Ctrl-C = terminate Ctrl-Z = suspend ** Show all processes ps auxw Send a signal to any process kill [-sig] pid More advanced job control jobs = list all jobs (children) started by this shell fg %n = resume in foreground ** bg %n = resume in background

Summary Processes identified by pid Each process at start gets 3 things: Environment variables, e.g. HOME="/home/you" Open files Arguments You can send signals to a running process At end it returns a numeric exit code Shell gives you control of these things

Practical Exercise 1

Processes and security Each process runs with set privileges effective uid effective gid supplementary groups Some operations are only available to root e.g. bind socket to port below 1024 e.g. shut down system A process running as root (euid=0) can change to any other uid - but not back again Other processes cannot change uid at all!

How do users change passwords? Note that /etc/master.passwd is only readable and writable by root The 'passwd' program has special privileges, it is marked "setuid root" Whenever a user starts the 'passwd' program, kernel gives it euid=root It can then change the user's password setuid programs must be written very carefully to avoid security holes Don't fiddle with setuid bits

Aside... It's really useful to think of commands in pairs The command which shows a setting and the command which changes that setting Example: pwd shows the current working directory cd changes the current working directory Follow the 3-step system for changes Check things are how you think they are Make the change Check things have changed as you expected

Commands for managing files Show which files exist: ls Show detail (long form): ls -l Manipulating files: cp, mv, rm Which editor to use? vi clunky but always available ee FreeBSD-specific joe has to be installed as a separate package

The Virtual Filesystem (VFS) All filesystems appear in a single tree Must have a root device - / Can attach other devices at other points At bootup, everything in /etc/fstab is mounted except lines marked 'noauto'

Key VFS commands Show status mount df Attach device mount -t cd9660 /dev/acd0 /cdrom /cdrom is called the "mount point" it's just an empty subdirectory after mounting, the filesystem contents appear here Detach device umount /cdrom

Other devices Formatting a floppy disk fdformat /dev/fd0 newfs_msdos -L myfloppy /dev/fd0 Mounting a floppy disk mount -t msdos /dev/fd0 /mnt USB pen mount -t msdos /dev/da0s1 /mnt typical example look in /var/log/messages to check device use 'fdisk /dev/da0' to look at slices

Filesystem safety DON'T remove any media until it has been unmounted Otherwise, filesystem can be corrupted Kernel won't let you unmount a filesystem if it is in use Use 'fstat' to find processes using it ALWAYS shut down properly Filesystem repair tool is called "fsck"