Introduction to Operating Systems - Seneca

Download Report

Transcript Introduction to Operating Systems - Seneca

Introduction to Programming
Using C
An Introduction to
Operating Systems
Contents



2
Operating Systems
Files & Directories
UNIX Commands
Operating Systems



Computer hardware does nothing without
instructions
In the early days, one would press a button
to have the computer load and execute your
program
This had disadvantages
–
–
3
You could only run one program at a time
A human had to press a button to start a program
Operating Systems

This was a drag so they wrote a program to
run continuously and
–
–
–
–

4
Automate the loading of programs
Let more than one program run at once
Support multiple users
Make hardware transparent so that all disk drives
look alike even if made by different companies
This program was called an operating
system
Operating Systems

A computer is like an onion
–
–
–
5
Application programs are at the
outer layer
They talk to the operating
system at the next level
The operating system talks to
the hardware in the centre
hardware
UNIX



6
UNIX is an operating system written in the
1970s by AT&T
It has become a standard on which many
other operating systems are modelled
We will be using a command-line interface to
communicate with UNIX
Shells



While an application can talk to the OS, how
does a user talk to the OS
Via a special application called a shell
Shells fall into two broad categories
–
Command line shells

–
Graphical shells

7
Sh, csh, ksh
X Windows
Command Line Shells

A command line shell is a program which
–
–
–

8
Lets you type commands
Conveys your instructions to the operating system
Displays results from your programs and the
operating system
Shells have their own simple command
language which you use to tell them what to
do
Files and Directories




Everything you store in a computer is in a file
Files are given a name and are usually
stored on a hard disk
Files are organized into directories
A directory can contain
–
–
9
Any number of files
Other directories
Files and Directories



Files and directories are
organized into a tree like
structure
“/” is the root of the file
system
“/” is also used to specify a
path through the file system
/
usr
etc
rob
ipc144
10
home
Your Home Directory



11
Every user is assigned a home directory
This is a directory in which they can store
their files
Usually, a subdirectory is created for every
course and subdirectories in each course for
each assignment
Shells




12
A shell is the program which communicates
the user’s wishes to the operating system
We will be using the Korn Shell
This is a command-line interface
Command line interfaces are programmable,
making them useful for many tasks for which
GUIs are poorly suited
Logging In

You can contact the computer
–
–
Via a connected terminal
Over the internet via



Once connected you login with a
–
–
13
telnet – a remote terminal
Putty – a secure connection which is encrypted
User name
password
Listing Files


To see the files in your directory use the ls
command
This has variations, specifified with command
line parameters
–
–
14
ls –a
ls –l
list all files, including hidden ones
long listing showing details
Working with Directories

Directories and files are named with either a
relative or absolute path
–
Relative paths specify a file relative to the current
directory

–
Absolute paths give a complete path from the root
of the file system and do not depend on the
current directory

15
ipc144/as1/as1.c
/home/rob/ipc144/as1/as1.c
Working with Directories

You can find out what directory you are in by
typing
–

To change the currect directory
–
–
–
16
pwd
cd <path>
“.” is shorthand for the current directory
“..” is shorthand for the parent directory
Command Syntax

Every command
–
–
Starts with a command name
Is followed by



17
Options
Filenames or other data passed to the command
Optional input / output redirection
I/O Redirection

Every command reads input from
–

And write output to
–

–
18
Standard output
Normally, these are connected to
–

Standard input
The keyboard
The terminal screen
However, they can be redirected to files
I/O Redirection

The “<“ sign tells a program to read from a
file rather than the keyboard
–
–

The “>” sign redirects output to a file
–
–
19
cat < file1.txt
This causes the cat command to read from
file1.txt
cat > file2.txt
Causes the cat command to write its output to
file2.txt
End Of File




20
A file is simply a stream of bytes
Every file has and end marker called End Of
File
Your programs can detect this
When reading from a terminal, typing CTRLD on a line by itself and pressing RETURN
will send an End Of File character to your
program
Shell Programming



Shell commands can be saved in files and
replayed at any time
The shell maintains variables to make
programming easier
Common variables include
–
–
–
21
HOME -- your home directory
PATH -- directories searched for commands
PS1
-- prompt
Shell Programming

You can set a variable by simply assigning a
value
–

To see the value type
–

Echo $Myvar
To see the values of all variables type
–
22
Myvar=1
set
Basic UNIX Commands

cat [<filelist>]
–
–
–

cd [<dir>]
–
–
23
Concatenates one or more files into a single file
Often used to display a file on screen
Also used to combine files
Changes the current working directory to the
absolute or relative path specified
All relative paths are prefixed with the current
directory
Basic UNIX Commands

chmod <permissions> <filelist>
–
–
Every file has an owner and a set of permissions
You can allow a file to be



–
These operations can be performed by




24
Read (r)
Written (w)
Executed (x)
The owner (u)
The group (g)
Everyone outside the owner or his/her group (o)
All users (a)
Basic UNIX Commands

The permissisons are combined into a string
of the form
–

To allow anyone to read a file
–

chmod a+r filename
Restrict access to anyone but the owner
–
25
[rwx]±[oug]
chmod ug-rwx filename
Basic UNIX Commands

clear
–

cp <filelist> <dest>
–
–

Copies one or more files to another file or
directory
Can be used to copy files to a directory
df
–
26
Clears the screen
Shows the amount of free disk space
Basic UNIX Commands

du [<dir>]
–

finger <user>
–

Provides information about a user
ln <filename> <alias>
–
27
Reports the disk usage for a directory
Creates a link where two filenames point to the
same file
Basic UNIX Commands

lpr [-P printer] <filelist>
–

lpstat [-P printer]
–

Lists jobs queued for the printer
ls [-al]
–
28
Prints a series of files on a printer
Lists files in a directory
Basic UNIX Commands

man <command>
–

mkdir <dirlist>
–

Provides a manual page on the command
Creates one or more new directories
more <filelist>
–
Displays a file a screenful at a time



29
Enter advances one line
Space advances one page
q quits
Basic UNIX Commands

mv <filelist> <dest>
–
–

passwd
–

Allows you to change your password
pwd
–
30
Moves files rather than copying
Can be used to rename a file
Displays the current directory name
Basic UNIX Commands

quota
–

rm <filelist>
–

Removes a directory if it is empty
set
–
31
Removes one or more files
rmdir <dirlist>
–

Displays how much disk space you can use
Displays all shell variables
Basic UNIX Commands

stty
–

who
–
32
Terminal settings
Shows who is logged on
Editing

UNIX has a variety of editors
–
vi

–
nled

–
Neat little editor
Pico

33
Everyone loves to hate this one
Another editor
Compiling

The C compiler is called cc
–
–
–
–
34
cc <cfilelist> –o <outputfile>
Compiles one or more C source files into an
executable output file
Output files do not have to end in .exe
Write errors to command line
35