chapter 2 – introduction (pgs 49 – 91). system services - user user interface: usually cli or...

18
CSCI 3431: OPERATING SYSTEMS Chapter 2 – Introduction (Pgs 49 – 91)

Upload: tracy-fields

Post on 30-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

CSCI 3431: OPERATING SYSTEMS

Chapter 2 – Introduction (Pgs 49 – 91)

Page 2: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

System Services - User

User interface: usually CLI or GUI Program execution: start, stop, suspend,

resume I/O operations: to/from files or devices File-system operations: directories, files,

perms, links etc. Communications – interprocess and

intermachine Error detection (and

prevention/correction)

Page 3: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

System Services - Admin

Resource allocation: balancing, priorities

Accounting: monitoring, reporting, tuning

Protection and Security: access (perms & passwords), identification (userids), encryption, monitoring

Page 4: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

Interfaces

Command Interpreter – text interface cmd.exe in Windows bash, sh, bsh, ksh etc. in unix, os-x JCL on some mainframes Graphical for most users – won’t cover much Hardware-based for some embedded systems

(e.g., cell phone, cash register, airbus) Communication-based for some devices (e.g.,

modems, spacecraft) Not necessarily just one interface on a

system

Page 5: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

System Calls

Low-level tasks done by the O/S and which can be requested by programmers

Usually written in C, C++, and occassionally assembly language

In Unix, they look just like library functions#include <fcntl.h>

result = open(“/usr/tami/file1.c”, O_RDONLY);

System programmers are intimately familiar with the system calls on their system

Future programming exercises will heavily focus on these!!!

Page 6: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

SysCall Categories

1. Process control: fork, wait, exit2. File manipulation: open, read, write,

close3. Device manipulation: ioctl, read,

write4. Information maintenance: getpid,

alarm5. Communications: pipe, shmget,

mmap6. Protection: chmod, umask, chown

Page 7: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

System Programs

Often just wrappers around SysCalls GUIs are wrappers for the CLI

versions1. File management: mkdir, cp, mv,

cat2. Status information: ps, df, du3. File modification: nano, vi, emacs4. Programming support: awk, gcc,

gdb, gprof5. Prog. Loading & execution: ld6. Communications: ssh, talk

Page 8: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

Operating System Design

User goals: What balance of the factors do the users need/expect?

Roles: What tasks must it be able to fulfill? What will it be used for?

Constraints: Time, money, platform ...

Risks: What are the major risks that must be considered?

No different to any other Soft. Eng. task

Page 9: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

Levels of Concern

Policy – How the O/S will be used. May vary with deployment. Flexibility is often very important here, e.g., parameter to control the length of a time slice

Mechanism – How the O/S will fulfill its goals, e.g., timer to measure a time slice

Implementation – How the programmer will implement the mechanism, e.g., link timer to clock interrupts vs. busy waiting

Page 10: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

Structures

Simple or Monolithic – O/S is one huge program

Layered – may require h/w support (e.g., protected/privileged modes), good idea, but complicated

Microkernel – minimise O/S (mostly communication, process, memory mgmt), put everything else into support service programs

Page 11: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

Modular System

Basic Microkernel-like core Modules loaded at boot/run-time for

other tasks Modules can communicate directly

(saves message passing) Modules have clean interfaces (gets

many advantages of layers) Only needed modules are loaded

(saves space)

Page 12: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

Virtual Machines

Stick a layer between the O/S and the hardware (like a hardware simulator)

Run multiple O/S on this layer First seen in IBM VM/CMS O/S Layer does not have to simulate the

hardware its sitting on – it can simulate some different platform (e.g., to support development)

Best example is VMware SGG include JVM – Why is this kind of silly?

Page 13: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

Debugging an O/S

Really, really, hard! Often done with hardware simulators Core dump – memory contents when failure

occurred, but, its the O/S that does this! Crash = O/S kernel failure Crash dumps often use a special disk partition

that can be corrupted and has no file system O/S often provide “hooks” that other tools can

connect to in order to obtain status info Windows lets you monitor the O/S via a USB

connection from another computer

Page 14: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

SysGen – Installing an O/SO/S on installation media needs to be

tailored for specific hardware platform and usage

CPU(s)Disk format, partitions, file systemsMemory size, structure (NUMA)Devices, interrupts, addressesUser choice of options (e.g., GUI)

Page 15: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

To Do:

Finish reading Chapter 2 if you haven`t (pgs 49-91; this lecture): All material is testable

Read Chapter 3 (pgs 101-141; next weeks lectures)

Ensure you can write and compile simple C programs with system calls.

Page 16: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

A System Call Example/* Lab 2 Solution, by Tami Meredith, 2011 */

#include <stdio.h>

#include <stdlib.h>

#include <sys/stat.h>

#include <unistd.h>

#include <string.h>

#define DEBUG 0

#define SUCCESS 0

#define FAILURE 1

#define BADUSE 2

#define BADFILE 3

#define BADPERMS 4

Page 17: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

char *appname;

void error (char *msg, int code) {

fprintf(stderr,\

"%s: Error: %s\nAborting\n", appname, msg);

exit(code);

} // end error ()

void usage (int code) {

fprintf(stderr,\

"Usage: %s <file> <perms>\n", appname);

exit(code);

} // end usage ()

Page 18: Chapter 2 – Introduction (Pgs 49 – 91). System Services - User  User interface: usually CLI or GUI  Program execution: start, stop, suspend, resume

int main (int argc, char** argv) {

char *file;

int mode;

struct stat sbuf;

appname = argv[0];

if (argc != 3) { usage(BADUSE); }

file = argv[1];

if (sscanf(argv[2], "%o", &mode) != 1) {

error ("Invalid permissions used", BADPERMS);

}

if (stat(file, &sbuf) == -1) {

error("File not found", BADFILE);

}

if (chmod(file, mode) == -1) {

error("Failed to change permissions", FAILURE);

}

return(SUCCESS);

} // end main ()