0% found this document useful (0 votes)
7 views25 pages

Chapter 01

The document provides an introduction to Unix, detailing its definition as a modern operating system that acts as an intermediary between users and hardware. It outlines the history of Unix, its development, and the significance of its open-source nature, as well as the structure of Unix systems including the kernel and shell. Additionally, it covers user account management, command execution, and the importance of logging out after use.

Uploaded by

ismaildumlu27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views25 pages

Chapter 01

The document provides an introduction to Unix, detailing its definition as a modern operating system that acts as an intermediary between users and hardware. It outlines the history of Unix, its development, and the significance of its open-source nature, as well as the structure of Unix systems including the kernel and shell. Additionally, it covers user account management, command execution, and the importance of logging out after use.

Uploaded by

ismaildumlu27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

System Programming

Introduction to Unix

Slides from Assoc. Prof. Dr. Hüseyin Pehlivan Karadeniz Technical University

Chapter One Introduction to Unix 1


Recommended Course Textbooks
n S. G. Kochan, P. Wood (2003)
Unix Shell Programming, 3rd Edition,
Sams, 460 p.

n R. K. Michael (2003)
Mastering UNIX Shell Scripting, Wiley,
680 p.

n W. R. Stevens, S. A. Rago (2005)


Advanced Programming in the Unix
environment, 2nd Edition, Addison
Wesley, 960 p.

n K. A. Robbins, S. Robbins (1996)


Practical Unix Programming, Prentice
Hall, 658 p.

Chapter One Introduction to Unix 2


What is Unix?
n A modern computer operating system
n Operating system
n “a program that acts as an intermediary between
a user of the computer and the computer
hardware”
n Software that manages your computer’s
resources (files, programs, disks, network, …)
n Examples: Windows, MacOS, Solaris, BSD, Linux
(e.g. Mandrake, Red Hat, Slackware)
n Modern
n Stable, flexible, configurable, allows multiple
users and programs

Chapter One Introduction to Unix 3


Why Unix?
n Used in many scientific and industrial
settings
n Huge number of free and well-written
software programs
n Open-source operating system (OS)
n Excellent programming environment
n Largely hardware-independent
n Based on standards
n Internet servers and services run on Unix
n Roughly 65% of the world’s web servers are
Linux/Unix machines running Apache

Chapter One Introduction to Unix 4


Brief History of Unix
n Ken Thompson & Dennis Richie
originally developed the earliest
versions of Unix at Bell Labs for
internal use in 1970s
n Simple and elegant
n Borrowed best ideas from other OSs
n Meant for programmers and computer
experts
n Meant to run on “mini computers”

Chapter One Introduction to Unix 5


Early Unix History
n Thompson also rewrote the operating
system in high level language of his own
design which he called B.
n The B language lacked many features and
Ritchie decided to design a successor to B
which he called C.
n They then rewrote Unix in the C
programming language to aid in portability.
n Small portion written in assembly language
(kernel)
n Remaining code written in C on top of the
kernel

Chapter One Introduction to Unix 6


Unix History
n Multics 1965
n First Edition 1971 (AT&T) (CACM 1974, 365-375)
n 1BSD 1977 (Berkeley)
n Sixth Edition 1975 (AT&T)
n 4BSD 1980 (Berkeley)
n SunOS 1985 (Sun)
n System V 1985 (AT&T)
n Tenth Edition 1989 (AT&T)
n 4.3BSD Net/2 1991 (Berkeley)
n First Linux kernel 1992 (Linus)
n Solaris 1993 (Sun)
n FreeBSD-1.0 1993
n NetBSD-1.0 1994
n OpenBSD-2.0 1996
n Max OS X 10.1 2001 (Apple)

Chapter One Introduction to Unix 7


Unix versions
n Two main threads of development:
n Berkeley software distribution (BSD)
([Link]
n Unix System Laboratories
([Link]
n BSD
n SunOS 4, Ultrix, BSDI, OS X, NetBSD, FreeBSD,
OpenBSD, Linux (GNU)
n SYS V
n System V (AT&T -> Novell -> SCO), Solaris
(SunOS 5), HP-UX (Hewlett-Packard), AIX

Chapter One Introduction to Unix 8


Brief History of Linux
n Andrew Tanenbaum, a Dutch professor developed
MINIX to teach the inner workings of operating
systems to his students
n In 1991 at the University of Helsinki, Linus Torvalds,
inspired by Richard Stallman’s GNU free software
project and the knowledge presented in Tanenbaum’s
operating system, created Linux, an open-source,
Unix-based operating system
n Over the last decade, the effort of thousands of open-
source developers has resulted in the establishment of
Linux as a stable, functional operating system

Chapter One Introduction to Unix 9


Layers in a Unix-based System

User Interface

Users
Library interface

Standard Utility Programs


(shell, editors, compilers, etc.)
System interface calls User Mode
Standard Library
(open, close read, write, etc.)
Unix Operating System
(process management, memory management, Kernel Mode
file system, I/O, etc.)
Hardware
(CPU, memory, disks, terminals, etc.)

Chapter One Introduction to Unix 10


Unix Structure
n The kernel is the core of the Unix
operating system, controlling the
system hardware and performing
various low-level functions. Other
parts of a Unix system (including user
programs) call on the kernel to
perform services for them.
n The shell accepts user commands and
is responsible for seeing that they are
carried out.

Chapter One Introduction to Unix 11


Unix Structure (cont.)
n Over four hundred utility programs or
tools are supplied with the Unix
system. These utilities (or commands)
support a variety of tasks such as
copying files, editing text, performing
calculations, and developing software.
n This course will introduce a limited
number of these utilities or tools,
focusing on those that aid in software
development.

Chapter One Introduction to Unix 12


Getting started

Chapter One Introduction to Unix 13


The Unix Account
n Logging in to a Unix machine requires
an account on that system.
n A user account is associated with
login and password.
n “login” is your user name (usually
some variant of your real name)
n Your password will not echo as you
type
n Remember good password practices

Chapter One Introduction to Unix 14


Logging into a UNIX system
init (Process ID 1 created by the kernel at bootstrap)
spawns getty for every terminal device
getty opens terminal device, sets file
descriptors 0, 1, 2 to it, waits for a user name,
usually sets some environment variable (TERM)
invokes login when user name entered
login reads password entry (getpwnam()), asks
for user’s password (getpass()) and validates it;
changes ownership of our terminal device,
changes to our UID and changes to our home
directory. Sets additional environment variables
(HOME, SHEL, USER, LOGNAME, PATH)
invokes our login shell

Login shell (bash)

Chapter One Introduction to Unix 15


How Logins were processed
n init (using /etc/ttys or /etc/inittab) -> forks and execs getty
programs on each terminal
n getty gets user name -> execs login
n login verifies password -> execs login shell
n User uses login shell

n Login methods: Using an X display


n User logins in via getty/login, then runs startx
n xdm -- reads username & passwd, starts X as that user
n Somewhat like a startx without the login shell
n Can start a "terminal" (or shell) window

Chapter One Introduction to Unix 16


Secure Login Tools
n Terminal connection
n PuTTy (on Windows)
n MindTerm (Java applet)
n Desktop connection
n X-Win32
n CDE, KDE, GNOME
n WeirdX (Java application)
n File transfer
n WinSCP3
n SmartFTP

Chapter One Introduction to Unix 17


What is a Shell?
n Just a Unix program executed when you log in
n A command interpreter
n provides the basic user interface to UNIX utilities
n A programming language
n program consisting of shell commands is called a
shell script
n you can put commands in a file and execute it:
n First, make the file executable (chmod u+x script−file)
n Lines starting with # are comments

n Make use of interpreter files (kernel feature!): the first line


of your script file must begin with a line:
#!pathname optional−arguments
where pathname is an absolute pathname (typically /bin/sh,
or /bin/bash) of the interpreter.

Chapter One Introduction to Unix 18


The Shell Prompt
n After logging in, some information
about the system will be displayed,
followed by a shell prompt, where
commands may be entered
n $
n %
n #
n username@hostname>
n hostname %

Chapter One Introduction to Unix 19


The Shell
n The shell is the program you use to
send commands to the Unix system
n Some commands are a single word
n who
n date
n ls
n Others use additional information
n cat textfile
n ls -l
Chapter One Introduction to Unix 20
Command Syntax
n Commands must be entered exactly. If
you make a mistake before entering,
delete/backspace to fix it. Be careful!
n command options argument(s)
n Options modify a command’s execution
n Arguments indicate upon what a
command should act (often filenames)

Chapter One Introduction to Unix 21


Example Commands: ls (list)
n ls –l
n ls –a
n ls –la
n ls –a; ls –l
n ls -F
n ls –al textfile1
n ls –al textfile1 textfile2
n ls –al directory
Chapter One Introduction to Unix 22
Command Execution
n The current shell (bash)
n executes built-in commands (echo, kill, pwd, …)
or shell scripts invoked by the . (dot)
command: . shell-script
n calls fork() to create a new shell process
n sub-shell (bash)
n The sub-shell
n executes a shell script or
n calls exec() to execute a command or program
n terminates after script or command execution
n During command execution,
n the parent either waits, or continues if
command is executed in the background

Chapter One Introduction to Unix 23


No Shell Prompt
n If you don’t get a prompt
n A program is probably running
n If you see a special program prompt, try
to quit the program (quit, bye,
exit)
n If you see nothing, you can
n Stop the program with CTRL-Z (program
will wait until started again)
n Interrupt the program with CTRL-C
(program will usually die)
Chapter One Introduction to Unix 24
Logging Out
n Always log out when you are done
n Use the exit command to log out of
a shell (sometimes logout or CTRL-D)
n Note: if you are running in a
windowing environment, logging out
of the shell only ends that shell. You
must also log out of the windowing,
typically selecting an option from a
menu.
Chapter One Introduction to Unix 25

You might also like