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.

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
Using tcpdump. tcpdump is a powerful tool that allows us to sniff network packets and make some statistical analysis out of those dumps. tcpdump operates.
CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
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
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
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.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
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.
Processes & Daemons Chapter IV / Part III. Commands Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more.
University of Pennsylvania 9/12/00CSE 3801 Multiprogramming CSE 380 Lecture Note 3.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
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.
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
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.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
Linux+ Guide to Linux Certification, Third Edition
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
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.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
System calls for Process management
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.
System Administration – Part 2. Devices in UNIX are files: A device can be accessed with different file names All device files are stored in /dev or its.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
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)
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 9 Working.
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 2.
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 ( >, >>,
An Introduction to processes R Bigelow. A Unix Process A process in Unix is simple a program The Unix system is made up of a group of processes all interacting.
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.
...looking a bit closer under the hood
Implementation of a simple shell, xssh
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
Hands On UNIX AfNOG X Cairo, Egypt
Chapter 2: The Linux System Part 2
...looking a bit closer under the hood
CHAPTER 13 Processes.
Introduction Paul Flynn
Presentation transcript:

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 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)‏

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 Process control from the shell

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

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"