The Unix Shell. Job Control

Similar documents
The Unix Shell. Job Control

Unix Processes. What is a Process?

Linux Tutorial #6. -rw-r csce_user csce_user 20 Jan 4 09:15 list1.txt -rw-r csce_user csce_user 26 Jan 4 09:16 list2.

The Unix Shell. Permissions

The Unix Shell. Pipes and Filters

Linux Command Line Interface. December 27, 2017

Introduction to UNIX Shell Exercises

Exploring UNIX: Session 5 (optional)

CSC UNIX System, Spring 2015

Sperimentazioni I LINUX commands tutorial - Part II

Removing files and directories, finding files and directories, controlling programs

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Linux System Administration

bash, part 3 Chris GauthierDickey

Introduction to Linux

Lab 2: Linux/Unix shell

High Performance Computing Lecture 11. Matthew Jacob Indian Institute of Science

ACS Unix (Winter Term, ) Page 92

Systems Programming/ C and UNIX

Chapter 9: Process management. Chapter 9 Process management

HW 1: Shell. Contents CS 162. Due: September 18, Getting started 2. 2 Add support for cd and pwd 2. 3 Program execution 2. 4 Path resolution 3

I/O and Shell Scripting

5/8/2012. Controlling User Processes Chapter 10

Programs. Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic

CRUK cluster practical sessions (SLURM) Part I processes & scripts

File system Security (Access Rights)

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell.

Bamuengine.com. Chapter 7. The Process

Simplest version of DayOfYear

Most of the work is done in the context of the process rather than handled separately by the kernel

User Commands ps ( 1 )

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Unix Shell. Advanced Shell Tricks

The Unix Shell. Files and Directories

S E C T I O N O V E R V I E W

Introduction to the Linux Command Line January Presentation Topics

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Shells and Shell Programming

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction to the Shell

UNIX Tutorial Five

The Unix Shell & Shell Scripts

Shells and Shell Programming

Part 1: Basic Commands/U3li3es

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

Backgrounding and Task Distribution In Batch Jobs

Input/Output (I/O) Re-direction

Lecture 5: Jobs and Processes

Self-test Linux/UNIX fundamentals

Shells and Processes. Bryce Boe 2012/08/08 CS32, Summer 2012 B

CMU MSP 36602: Intro to UNIX and Scripting: Part 1

Linux shell scripting Getting started *

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Study Guide Processes & Job Control

Chap2: Operating-System Structures

CS197U: A Hands on Introduction to Unix

Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems

Configuring the Router ASCII Interface

Redirection and Pipes

Introduction to Linux

OPERATING SYSTEMS LINUX

Mills HPC Tutorial Series. Linux Basics II

Assignment clarifications

Configuring the ASCII Interface

Unix Basics. Systems Programming Concepts

07 - Processes and Jobs

Introduction To. Barry Grant

System Programming. Unix Shells

Review of Fundamentals

System Administration

Computer Systems and Architecture

Command Line Interface Techniques

Command-line interpreters

Managing Processes Process: A running program

Operating Systems Lab 1 (Users, Groups, and Security)

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Automated Builds. Rules

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Multitasking. In this chapter: Running a Command in the Backg round Checking on a Process Cancelling a Process

Linux 系统介绍 (III) 袁华

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

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

Process States. Controlling processes. Process states. PID and PPID UID and EUID GID and EGID Niceness Control terminal. Runnable. Sleeping.

unix intro Documentation

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Advanced Bash Scripting

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

Bioinformatics. Computational Methods I: Genomic Resources and Unix. George Bell WIBR Biocomputing Group

SOFTWARE ARCHITECTURE 3. SHELL

Getting started with Hugs on Linux

Bash Programming. Student Workbook

Chapter 3: Processes

Unix Introduction to UNIX

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

Running Programs in UNIX 1 / 30

Transcription:

The Unix Shell Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.

shell

shell $ wc l *.pdb sort -n head -n 1

shell $ wc l *.pdb sort -n head -n 1 wc sort head

shell $ wc l *.pdb sort -n head -n 1 wc sort head Control programs while they run

shell $ wc l *.pdb sort -n head -n 1 wc sort head processes Control programs while they run

A process is a running program

A process is a running program Some are yours

A process is a running program Some are yours Most belong to the operating system (or other users)

A process is a running program Some are yours Most belong to the operating system (or other users) Use ps to get a list

A process is a running program Some are yours Most belong to the operating system (or other users) Use ps to get a list $ ps PID TTY TIME CMD 11275 pts/16 00:00:00 bash 12092 pts/16 00:00:00 ps Process ID Command

A process is a running program Some are yours Most belong to the operating system (or other users) Use ps to get a list (in various formats) $ ps PID TTY TIME CMD 11275 pts/16 00:00:00 bash 12092 pts/16 00:00:00 ps See man ps $ ps ux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND vlad 11275 0.0 0.0 108608 1856 pts/16 Ss 14:59 0:00 -bash vlad 12096 0.0 0.0 108320 1016 pts/16 R+ 15:03 0:00 ps ux $ ps -F UID PID PPID C SZ RSS PSR STIME TTY TIME CMD vlad 11275 11224 0 27152 1856 1 14:59 pts/16 00:00:00 -bash vlad 12104 11275 0 27079 1016 5 15:03 pts/16 00:00:00 ps -F

Can stop, pause, and resume running processes

Can stop, pause, and resume running processes $./analyze results*.dat

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass...

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $ Stop the running program

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ Run in the background

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ Run in the background Shell returns right away instead of waiting for the program to finish

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ fbcmd events $ Can run other programs in the foreground while waiting for background process(es) to finish

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ fbcmd events $ jobs [1]./analyze results01.dat results02.dat results03.dat $

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ fbcmd events $ jobs Show background processes [1]./analyze results01.dat results02.dat results03.dat $

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ fbcmd events $ jobs [1]./analyze results01.dat results02.dat results03.dat $ fg

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ fbcmd events $ jobs [1]./analyze results01.dat results02.dat results03.dat $ fg Bring background job to foreground

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ fbcmd events $ jobs [1]./analyze results01.dat results02.dat results03.dat $ fg Bring background job to foreground Use fg %1, fg %2, etc. if there are several background jobs

Can stop, pause, and resume running processes $./analyze results*.dat...a few minutes pass... ^C $./analyze results*.dat & $ fbcmd events $ jobs [1]./analyze results01.dat results02.dat results03.dat $ fg...a few minutes pass... $ And finally it's done

Use ^Z to pause a program that's already running

Use ^Z to pause a program that's already running fg to resume it in the foreground

Use ^Z to pause a program that's already running fg to resume it in the foreground Or bg to resume it as a background job

Use ^Z to pause a program that's already running fg to resume it in the foreground Or bg to resume it as a background job $./analyze results01.dat

Use ^Z to pause a program that's already running fg to resume it in the foreground Or bg to resume it as a background job $./analyze results01.dat ^Z [1] Stopped./analyze results01.dat $

Use ^Z to pause a program that's already running fg to resume it in the foreground Or bg to resume it as a background job $./analyze results01.dat ^Z [1] Stopped./analyze results01.dat $ bg %1 $

Use ^Z to pause a program that's already running fg to resume it in the foreground Or bg to resume it as a background job $./analyze results01.dat ^Z [1] Stopped./analyze results01.dat $ bg %1 $ jobs [1]./analyze results01.dat $

Use ^Z to pause a program that's already running fg to resume it in the foreground Or bg to resume it as a background job $./analyze results01.dat ^Z [1] Stopped./analyze results01.dat $ bg %1 $ jobs [1]./analyze results01.dat $ kill %1 $

Job control mattered a lot when users only had one terminal window

Job control mattered a lot when users only had one terminal window Less important now: just open another window

Job control mattered a lot when users only had one terminal window Less important now: just open another window Still useful when running programs remotely

created by Greg Wilson August 2010 Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.

The Unix Shell Variables Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.

shell

shell The shell is a program

shell The shell is a program It has variables

shell The shell is a program It has variables Changing their values changes its behavior

$ set COMPUTERNAME=TURING HOME=/home/vlad HOMEDRIVE=C: HOSTNAME=TURING HOSTTYPE=i686 MANPATH=/usr/local/man:/usr/share/man:/usr/man NUMBER_OF_PROCESSORS=4 OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/bin PWD=/home/vlad UID=1000 USERNAME=vlad

$ set COMPUTERNAME=TURING HOME=/home/vlad HOMEDRIVE=C: HOSTNAME=TURING HOSTTYPE=i686 With no arguments, shows all variables and their values MANPATH=/usr/local/man:/usr/share/man:/usr/man NUMBER_OF_PROCESSORS=4 OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/bin PWD=/home/vlad UID=1000 USERNAME=vlad

$ set COMPUTERNAME=TURING Standard to use upper-case names HOME=/home/vlad HOMEDRIVE=C: HOSTNAME=TURING HOSTTYPE=i686 MANPATH=/usr/local/man:/usr/share/man:/usr/man NUMBER_OF_PROCESSORS=4 OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/bin PWD=/home/vlad UID=1000 USERNAME=vlad

$ set COMPUTERNAME=TURING HOME=/home/vlad HOMEDRIVE=C: HOSTNAME=TURING HOSTTYPE=i686 All values are strings MANPATH=/usr/local/man:/usr/share/man:/usr/man NUMBER_OF_PROCESSORS=4 OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/bin PWD=/home/vlad UID=1000 USERNAME=vlad

$ set COMPUTERNAME=TURING HOME=/home/vlad HOMEDRIVE=C: HOSTNAME=TURING HOSTTYPE=i686 MANPATH=/usr/local/man:/usr/share/man:/usr/man NUMBER_OF_PROCESSORS=4 OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/bin PWD=/home/vlad UID=1000 USERNAME=vlad All values are strings Programs must convert to other types when/as necessary

$ set COMPUTERNAME=TURING HOME=/home/vlad HOMEDRIVE=C: HOSTNAME=TURING HOSTTYPE=i686 MANPATH=/usr/local/man:/usr/share/man:/usr/man NUMBER_OF_PROCESSORS=4 OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/bin PWD=/home/vlad UID=1000 USERNAME=vlad int(string) for numbers

$ set COMPUTERNAME=TURING HOME=/home/vlad HOMEDRIVE=C: HOSTNAME=TURING HOSTTYPE=i686 split(':') for lists MANPATH=/usr/local/man:/usr/share/man:/usr/man NUMBER_OF_PROCESSORS=4 OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/bin PWD=/home/vlad UID=1000 USERNAME=vlad

PATH controls where the shell looks for programs

PATH controls where the shell looks for programs $./analyze Run the analyze program in the current directory

PATH controls where the shell looks for programs $./analyze $ /bin/analyze Run the analyze program in the /bin directory

PATH controls where the shell looks for programs $./analyze $ /bin/analyze $ analyze

PATH controls where the shell looks for programs $./analyze $ /bin/analyze $ analyze directories = split(path, ':') for each directory: if directory/analyze exists, run it

PATH controls where the shell looks for programs $./analyze $ /bin/analyze $ analyze directories = split(path, ':') /usr/local/bin /usr/bin /bin for each directory: if directory/analyze exists, run it /usr/bin/analyze

PATH controls where the shell looks for programs $./analyze $ /bin/analyze $ analyze directories = split(path, ':') /usr/local/bin /usr/bin /bin for each directory: if directory/analyze exists, run it (and then stop searching) /usr/bin/analyze (/bin/analyze)

echo prints its arguments

echo prints its arguments Use it to show variables' values

echo prints its arguments Use it to show variables' values $ echo hello transylvania hello transylvania $

echo prints its arguments Use it to show variables' values $ echo hello transylvania hello transylvania $ echo HOME

echo prints its arguments Use it to show variables' values $ echo hello transylvania hello transylvania $ echo HOME HOME $

echo prints its arguments Use it to show variables' values $ echo hello transylvania hello transylvania $ echo HOME HOME $ echo $HOME /home/vlad $

echo prints its arguments Use it to show variables' values $ echo hello transylvania hello transylvania $ echo HOME HOME $ echo $HOME /home/vlad $ Ask shell to replace variable name with value before program runs

echo prints its arguments Use it to show variables' values $ echo hello transylvania hello transylvania $ echo HOME HOME $ echo $HOME /home/vlad $ Ask shell to replace variable name with value before program runs Just like * and? are expanded before the program runs

echo prints its arguments Use it to show variables' values $ echo hello transylvania hello transylvania $ echo HOME HOME $ echo $HOME echo /home/vlad /home/vlad $

Create variable by assigning to it

Create variable by assigning to it Change values by reassigning to existing variables

Create variable by assigning to it Change values by reassigning to existing variables $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula $ SECRET_IDENTITY=Camilla $ echo $SECRET_IDENTITY Camilla $

Assignment only changes variable's value in this shell

Assignment only changes variable's value in this shell $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula $

Assignment only changes variable's value in this shell $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula $ bash $

Assignment only changes variable's value in this shell $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula $ bash $

Assignment only changes variable's value in this shell $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula $ bash $ echo $SECRET_IDENTITY $

Assignment only changes variable's value in this shell $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula $ bash $ echo $SECRET_IDENTITY $ exit $

Assignment only changes variable's value in this shell $ SECRET_IDENTITY=Dracula $ echo $SECRET_IDENTITY Dracula $ bash $ echo $SECRET_IDENTITY $ exit $ echo $SECRET_IDENTITY Dracula $

Use export to signal that the variable should be visible to subprocesses

Use export to signal that the variable should be visible to subprocesses $ SECRET_IDENTITY=Dracula $ export SECRET_IDENTITY $

Use export to signal that the variable should be visible to subprocesses $ SECRET_IDENTITY=Dracula $ export SECRET_IDENTITY $ bash $

Use export to signal that the variable should be visible to subprocesses $ SECRET_IDENTITY=Dracula $ export SECRET_IDENTITY $ bash $ echo $SECRET_IDENTITY Dracula $

Use export to signal that the variable should be visible to subprocesses $ SECRET_IDENTITY=Dracula $ export SECRET_IDENTITY $ bash $ echo $SECRET_IDENTITY Dracula $ exit $

Commands in $HOME/.bashrc are executed when shell starts

Commands in $HOME/.bashrc are executed when shell starts export SECRET_IDENTITY=Dracula export BACKUP_DIR=$HOME/backup /home/vlad/.bashrc

Commands in $HOME/.bashrc are executed when shell starts export SECRET_IDENTITY=Dracula export BACKUP_DIR=$HOME/backup Also common to use alias to create shortcuts

Commands in $HOME/.bashrc are executed when shell starts export SECRET_IDENTITY=Dracula export BACKUP_DIR=$HOME/backup Also common to use alias to create shortcuts alias backup=/bin/zarble -v --nostir -R 20000 $HOME $BACKUP_DIR

Commands in $HOME/.bashrc are executed when shell starts export SECRET_IDENTITY=Dracula export BACKUP_DIR=$HOME/backup Also common to use alias to create shortcuts alias backup=/bin/zarble -v --nostir -R 20000 $HOME $BACKUP_DIR Not something you want to type over and over

created by Greg Wilson August 2010 Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.