Agenda The Bourne Shell – Part I Redirection ( >, >>, <, <<) Pipes Controlling Processes Creating Subshells, ps, ps -l, $!, $$ Managing Processes (Jobs)

Slides:



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

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.
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI) Chapter 7: The Linux Shell By Fred R. McClurg Linux.
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.
Introduction to Unix – CS 21 Lecture 10. Lecture Overview Midterm questions Jobs and processes description The foreground and background Controlling jobs.
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 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
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.
The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log.
BIF703 Redirection Continued: Pipes. Redirection Recall from the previous slides we defined stdin, stdout, and stderr and we learned how to redirect these.
Guide To UNIX Using Linux Third Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
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.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>,
Guide To UNIX Using Linux Fourth Edition
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
An Introduction to Unix Shell Scripting
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Linux+ Guide to Linux Certification, Third Edition
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Process Control. Module 11 Process Control ♦ Introduction ► A process is a running occurrence of a program, including all variables and other conditions.
Agenda Getting Started: Using Unix Unix Structure / Features Elements of the Unix Philosophy Unix Command Structure Command Line Editing Online Unix Command.
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
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.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
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)
Linux Commands C151 Multi-User Operating Systems.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
Linux+ Guide to Linux Certification, Second Edition
BIF713 Introduction to Linux. Agenda Getting Started: Using Linux Unix and Linux - Structure / Features Elements of the Linux Philosophy Linux Command.
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
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.
ULI101 Week 05. Week Overview ● File system links ● Hard and symbolic links ● Process management ● Storage quota information (quota) ● Printing.
Foreground and background processes
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Introduction to Shells
...looking a bit closer under the hood
Hands On UNIX AfNOG 2010 Kigali, Rwanda
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands:
Shell Script Assignment 1.
stdin, stdout, stderr Redirection
Hands On UNIX AfNOG X Cairo, Egypt
Basic UNIX OLC Training.
Introduction to UNIX.
Linux Shell Script Programming
Chapter 3 The UNIX Shells
LPI Linux Certification
Presentation transcript:

Agenda The Bourne Shell – Part I Redirection ( >, >>, <, <<) Pipes Controlling Processes Creating Subshells, ps, ps -l, $!, $$ Managing Processes (Jobs) Command Grouping, Running jobs in background (bg), bringing jobs to foreground (fg), job status (jobs), Suspending jobs (CTRL Z), Restarting jobs in background, Displaying/Killing processes or jobs

The Bourne Shell The Bourne Shell was the first shell developed for the UNIX operating system. Since many other “new and improved” shells incorporate the Bourne shell, we will be learning about this shell first. When you login to PHOBOS, you can access the Bourne shell by issuing the command: sh (although you can use Bourne shell commands in the default shell for PHOBOS – which is the Korn Shell) There is no Bourne Shell in Linux…

Standard Input, Standard Output and Standard Error Three terms are used to indicate the direction of information when issuing UNIX / Linux commands: –Standard Input (stdin) – The default is the keyboard –Standard Output (stdout) – The default is the screen –Standard Error (stderr) – The default is the screen

Redirection Since everything in UNIX / Linux operating system is a file, standard input, standard output or the standard error can be directed from/to different files: 1>, >Redirects standard output to a file. The 1> indicates standard output is redirected, but “>” is considered “1>” by default. This will overwrite previous contents of a file unless you use “>>”

Redirection 2>Redirects the standard error to a file. This can be used to view error messages in a file for later reference. If you want to “throw-away” error messages, redirect to /dev/null commonly referred to as the “bit-bucket” or “trash can” Example: cat a b c 2> /dev/null

Redirection <Command takes input for a command from a file. Example: grep pattern < file 1 Can You explain the following redirections? cat file2 grep msaul file1 2> file7 grep dward file 5 2>/dev/null

Pipes ( | ) Pipes are used to send the standard output of one command into another command as the standard input Pipes have the advantage of modifying standard output to achieve a task (possibly without having to create temporary files which need to be removed later)

Controlling Processes A process in UNIX simply represents the running of a command The process structure in UNIX is similar to the hierarchical structure of directories: –The beginning process is root –Parent processes can create child processes –Processes can spawn other processes –When a child process is finished, execution returns to its parent process

Controlling Processes It is important to learn how UNIX processes work, since administering a UNIX system requires knowledge of how to start, stop and monitor processes. The UNIX system is built on a series of processes and sub-processes. If you don’t understand processes, you could accidentally shut down the UNIX system. (not a very smart or popular thing to do!)

Processes For your account, the basic process is the shell (although for the entire system - from root downwards there are many processes). When you type in a UNIX command and press ENTER, a child process is created to allow execution of command. During this time the parent process “sleeps” and resumes when child process is completed. There is even a command called sleep to suspend the process for a specific number of seconds!

Process Identification (PID) Process Identification Numbers (PIDs) are used to keep track of separate processes To view a compact listing of process ID numbers, you can enter ps To view a detailed listing of process ID numbers (relating child (PID)& parent processes(PPID)) enter ps -l To view listing of processes for the entire system, enter ps -ef

Read-only Variables for PIDs The shell can store the PID number as a read-only shell variable echo $$ displays the PID number that is currently executing echo $! displays the PID of the last process that was run in the background The next slide shows a practical example of using these read-only variables

Creating Filenames using $$ The PID number can be used to create unique filenames (that need to be different everytime they are run) To create temporary files within a script: cp file_name file_name.$$ This will create a temporary file with the PID as the extension. This is useful when removing all temp files (eg rm *.$$)

Managing Processes (Jobs) Command Grouping Running jobs in background (bg) brings jobs to foreground (fg) Displaying job status (jobs command) Suspending jobs (CTRL Z) Killing processes or jobs (kill)

Command Grouping You can run a set of commands on the same command line by typing such commands as: ls ; who ; date You can also, combine commands or files to be run in both the foreground or background (eg ls ; who or a & b ; c)

Command Grouping The UNIX OS has the ability to run programs in the foreground and in the background. This feature allows users of the UNIX system to run lengthy processes without interfering with their other tasks. To run a command or script in the background, type the symbol & after the command or filename (eg. who &). Note that spaces are allowed...

Command Grouping It is important to note that although these commands appear to be in a sequence, the shell may execute these in a different order may schedule jobs in a order For example, you may want to run both commands a & b in the background, and run command c in the foreground. Here is the command: (a;b)&c

Bringing processes to foreground When processes are run in the foreground, the shell will wait for the command to finish before allowing the user to enter another command (thus background processes are useful) If a process or processes are in the background (or suspended), you can bring it to the foreground by typing fg

Displaying job status (jobs command) You can display the status of jobs that are running in the background by typing the UNIX command jobs jobs commands give a listing of jobs running in the background: jobs with a plus sign “+” indicates default job to bring to foreground by entering fg Can bring numbered job to foreground by entering fg %(job#) - Note space between fg & %

Suspending jobs (CTRL Z) You can suspend or stop the execution of processes while they are running in the “foreground” by pressing When you press these keys, the process is suspended and placed into the background in order to free up the shell for other operations. You can resume process by bringing it to the foreground or have it run in background

Restarting Suspended Processes in the Background A process may take such a long time that it is better to suspend the job (i.e. send it to the background, and then have it run in the background). This will leave you to operate in the foreground If a process or processes are suspended in the background, you can have it continue running in the background by entering bg (rules such as bg %(job#) also apply)

Killing processes or jobs (kill) Depending on your permissions, you may be able to abort or “kill” a process. Only root is allowed to kill other user’s processes, but as a user, you can processes that you have created. Killing a process is also useful to halt processes that are running in the background since or DELETE keys in foreground won’t work

Procedure to “Kill” a Process Procedure: –We are assuming that you are killing one of your own process (you are logged in…) –View process by typing ps -l –Carefully locate PID to kill –Type kill %(job#) to kill that job number (can also use kill PID or kill -9 PID to kill process. The kill command by itself kills more recent stopped job