Transcript job number
18 Exam revision
Unix and Software Tools
Lecture 18
Mauro Jaskelioff
In This Lecture
• Exam format
• Main topics
• How to revise
Exam revision
Exam format
• Answer ONE compulsory question and TWO
other questions (three questions out of five)
• Each question is worth 20 points
• I will only mark three questions in the order
you answer them
• (So cross out any answers you don’t want
marked)
• Final mark for the module is your coursework
mark (at most 40) plus your exam mark (at
most 60).
Exam revision
Main topics
•
•
•
•
•
•
UNIX commands
Regular Expressions
Shell scripting
sed
AWK
Version Control Systems, Debuggers
and Make
Exam revision
How to revise
• Review all the coursework exercises and
the lab exercises.
• There is no previous exam. Look at the
sample questions (in the shared folder)
• If you get stuck with some previous
questions, send me an email – I will
either answer by email or, if I get a lot
of similar questions, arrange a tutorial
Exam revision
Sample Questions
• There are some sample questions in the
shared directory
• Note that questions won't differ much
from the style of questions you
answered in the coursework and during
the labs.
• Except there will be some theoreticaloriented questions.
Exam revision
Revision
• Network commands
• Processes and signals
Exam revision
Network Commands
• The main network commands are:
•
•
•
•
telnet and its secure version ssh
ftp and its secure version sftp
ping
traceroute
• We've mentioned others:
• nc
• finger (works over the network!)
Exam revision
Computer networks
• Computer networks are usually packet
switched and divide the responsibility of
delivering the information in several layers.
• The most widespread family of protocols for
computer networks is TCP/IP.
• IP (Internet Protocol) is in charge of routing
the packet to destination.
• TCP (Transmission Control Protocol) is in
charge of making the transmission reliable.
• Computers have numbers as addresses, but
are given memorable names using DNS
(Domain Name System).
Exam revision
Telnet
• Client – Server application
Telnet protocol
Client
(application on the
machine you use)
Exam revision
Server
(application accepts instructions
from client and returns data)
Telnet Client
• These applications turn the local
computer into a dumb terminal.
• Used for remote access to user
accounts.
• E.g.:
telnet unnc-cslinux.nottingham.edu.cn
• (N.B. telnet is not supported in CS! - WHY?)
Exam revision
Telnet Server
• Typically a UNIX machine
• Also on some networking devices, like
routers and switches
• Runs on port 23
• Allows clients access to a more powerful
computer, or a computer without screen
(like a router)
Exam revision
Telnet Disadvantages
• Telnet was one of the first internet
applications.
• It transfers data as ASCII text
• What is ASCII text?
• This means that information passed
across the internet using telnet is open
and insecure.
• Need a more secure alternative!
Exam revision
SSH (Secure SHell)
• ssh is another application protocol
• allows secure, encrypted communications between
remote computers.
• NOTE: the network doesn’t need to be secure, the
SSH protocol and applications ensure the security
themselves.
• There are commercial, Open Source and
Freeware applications.
• Example: Putty
Exam revision
SSH command line access
• ssh <username>@robin.cs.nott.ac.uk
• The first time you access an unknown host,
the ssh client will ask you if you want to
proceed and authorise the host “yes/no”. Type
‘yes’ and press enter.
• This will generate the encryption key that will
allow for a secure connection.
Exam revision
FTP (File Transfer Protocol)
• Allows you to transfer files between your client
FTP application and an FTP server.
• ftp robin.cs.nott.ac.uk
• You will be prompted for a username and password
• Some servers allow anonymous FTP
• These allow anyone access to the files stored
(obviously nothing sensitive or private will be
stored!)
• For anonymous FTP, you enter “anonymous” as your
username and anything for your password (entering
your email address is polite)
Exam revision
FTP (2)
• The ftp utility has its own set of UNIX
like commands which allow you to
perform tasks such as:
•
•
•
•
•
Connect and login to a remote host
Navigate directories
List directory contents
Put and get files
Transfer files as ascii, ebcdic or binary
Exam revision
FTP Disadvantages
• However like Telnet, FTP is an insecure
protocol as it transmits data (including
your password) as ASCII text.
• Like telnet, we need a more secure
system, enter SFTP!
Exam revision
SFTP (Secure File Transfer
Protocol)
• SFTP like FTP allows you to transfer files
between networks.
• Unlike FTP, it uses the SSH transport
protocols – hence SFTP transfer is
encrypted and secure
• E.g.: sftp [email protected]
• (OR use SSH Secure Copy, scp)
Exam revision
ping
• Sends an echo request to a network
host.
• It is useful for:
• Determining the status of the network and
various foreign hosts
• Tracking and isolating hardware and
software problems
• Testing, measuring, and managing
networks
Exam revision
ping (2)
• The ping command sends one
datagram (packet of information) per
second and prints one line of output for
every response received.
• Round-trip times and packet loss
statistics are calculated and displayed.
Exam revision
ping Example
% ping kanaha
PING kanaha.mhpcc.edu: (164.122.27.33): 56 data bytes
64 bytes from 164.122.27.33: icmp_seq=0 ttl=254 time=3 ms
64 bytes from 164.122.27.33: icmp_seq=1 ttl=254 time=2 ms
64 bytes from 164.122.27.33: icmp_seq=2 ttl=254 time=2 ms
64 bytes from 164.122.27.33: icmp_seq=3 ttl=254 time=2 ms
64 bytes from 164.122.27.33: icmp_seq=4 ttl=254 time=2 ms
64 bytes from 164.122.27.33: icmp_seq=5 ttl=254 time=2 ms
^C
----kanaha.mhpcc.edu PING Statistics---6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 2/2/3 ms
Exam revision
Traceroute
• traceroute works as ping but printing
the route taken to the target host.
traceroute www.google.cn
traceroute to cn.l.google.com (59.151.21.100), 30 hops max, 38 byte
packets
1 10.252.0.11 0.580 ms 0.520 ms 0.516 ms
2 10.254.0.11 1.188 ms 1.203 ms 1.194 ms
3 220.191.168.17 2.181 ms 1.863 ms 2.222 ms
4 61.174.69.101 3.711 ms 2.894 ms 2.513 ms
5 61.174.69.49 46.508 ms 8.999 ms 4.599 ms
6 202.97.41.237 11.754 ms 202.97.41.245 11.809 ms 11.681 ms
.
.
.
Exam revision
finger (Revisited)
• The finger command displays information
about users on a given host
• The host can be either local or remote:
$ finger [email protected]
Login name: mjj
In real life: Mauro J Jaskelioff
Directory: /stud/pg/mjj
Shell: /usr/local/bin/bash
On since May 22 10:46:31 on pts/65 from 220.191.168.13
No unread mail
No Plan.
Exam revision
Processes
• A process is an instance of a running program
• A program and a process are different things.
wc is a program; each time you run the
program wc, that creates a new process.
• A process runs until it has finished or is killed
• Every process has a number assigned to it
called a process–ID or PID.
Exam revision
Listing Processes
• ps
PID TTY
4073 pts/23
16007 pts/23
TIME CMD
00:00:00 bash
00:00:00 ps
• ps list all the processes attached
to the current terminal
Exam revision
Being “nice” to other people!
• If you are running a program on a shared
machine and you know it will take some time “nice” it
• nice will run a program at a lower priority so
that it doesn’t clog up the CPU
• Priorities range from 19 to -20
• -20 is the highest priority, but you are not
allowed to set priorities below 0 unless you are
root
$ nice –n 20 find . -name unix.ps –print
Exam revision
UNIX Signals
• Signals are a UNIX mechanism for controlling processes
• They can be generated automatically by events, or
generated by the user with the kill command
• kill sends a signal to a process
• kill <signal number> <PID>
• E.g. kill -15 25718
• “-15” is the signal number – here, it means “stop the
process cleanly” (i.e. close any files it is using)
• “-9” means “kill the process whatever”
• Useful if all else fails!
• The name of the command is kill because the default
signal is to terminate the process, effectively "killing" it.
Exam revision
Signal Numbers
• Each signal has a default action associated with
it
• Most signals can be caught from within a
program. A programmer can then:
• Ignore signal
• Perform the default action
• Execute a program specified function
• The default action can be
•
•
•
•
Term
Ign
Core
Stop
Terminate the process.
Ignore the signal.
Terminate the process and dump core.
Stop the process.
Exam revision
Signal Numbers
Signal
Name
Numbe
r
Default
Action
Meaning
SIGHUP
1
Term
Hangup (sent to a process when a modem
or network connection is lost, terminal is
closed, etc)
SIGINT
2
Term
Interrupt (generated by Ctrl-C)
SIGTRAP
5
Core
Trace trap
SIGKILL
9
Term
Kill
SIGBUS
10
Core
Bus error (invalid memory reference)
SIGSEGV
11
Core
Segmentation violation
SIGTERM
15
Term
Software termination signal (default kill
signal)
For a complete reference see the section 7 of the manual on signal
Exam revision
$ man 7 signal
Running a Process in the
Background
To use your command line while running a
process you can run it in the background:
• & puts a process in the background (detaches it
from the terminal)
• E.g. emacs &
Exam revision
Suspending Processes
• Processes can be temporarily suspended
• Use Ctrl-Z
• To restart a process type one of:
• fg (puts process back in the foreground)
• bg (will restart process, but in the background)
• Suspended processes can also be killed:
• Do a process listing
• Use the kill command with the process ID
Exam revision
Job Control
• The jobs command produces a numbered list of
background and suspended processes
• You can use these job numbers to access your jobs:
[zlizmj@unnc-cslinux ~]$ jobs
[1]
- Running
xclock -d
[2]
+ Suspended more temp.txt
[zlizmj@unnc-cslinux ~]$ kill %2
[zlizmj@unnc-cslinux ~]$ jobs
[1]
- Running
xclock -d
• Note
that
the
job
number
is
not
the process ID!
[3]
Terminated
more temp.txt
Exam revision
Job Control (2)
• jobs allows you to:
• Bring a job to the foreground
• fg %<job number>
• Run a job in the background
• bg %<job number>
• Suspend a job
• stop %<job number>
• Terminate a job
• kill %<job number>
Exam revision
Scheduling Processes - cron
• Processes can be scheduled to run at a
periodic intervals:
• Use the cron daemon
• With this, users can schedule processes to
run periodically, or at specified times
• Create a text file called crontab.cron which
contains lines with a date/time and
command line
• You have to register your crontab using the
command crontab crontab.cron in order
for the cron daemon to activate your
crontab
Exam revision
Scheduling Processes - cron (3)
• Each line in crontab.cron has five fields:
•
•
•
•
•
•
Minute - (0-59)
Hour - (0-23)
Day of the month - (1-31)
Month of the year - (1-12)
Day of the week - (0-6) (Sunday is 0)
Command line - the command to be
executed
Exam revision
Using cron
• Edit your crontab.cron file to contain
what you want it to do:
0,30 * * * 1-5 date >> datelog
• This cron job will record the date it was run
every 30 minutes from Monday to Friday, in
the file datelog
• Register your crontab:
$ crontab crontab.cron
Exam revision