Operating Systems Overview
** Read Chapter 2, pp.28-44, Chapter 3, pp.53-60
Kernels:
- critical core of OS
- operates in supervisor mode -> must be trusted
- generic system software and user apps execute in user mode
- programs in user mode request kernel services by:
- system call: x = fcn(a,b,..)/ return
- invokes trap, sets SU, when fcn done, resets SU and returns
- message passing: send(dest, a, b...)/receive(from, a, b,...)
- uses OS send/receive service (operates in supervisor mode)
- generally less efficient
- evolution of kernels:
- 60's: nonprocess kernel
- OS kernel is special program
- has its own memory, stack, etc.
- operates in its own privledged mode
- 70's: kernel executed within user process
- common for small minicomputers, PCs
- typified by UNIX
- OS services accessed via normal subroutine calls
- require scheme to enter SUP to give OS access to resources
(and return to USER mode when done)
- 80's: microkernels
- minimal fast kernel that provides only basic services
- began with MACH (CMU)
- non-kernel modules communicate largely via message-passing
First puzzle of OS:
- OS controls usage of computer resources
- but being a program itself, must relinquish control of machine to let other
applications run
- how does it do this while remaining in charge?
- depends on HW/SW mechanisms to regain control
OS provides several important abstractions:
- process = fundamental unit of computation
- process != program
- can have several processes each running the same program
- similar to a "job" of the batch processing days
- process = represent'n of state of an instance of program in execution
- file = special resource: fundamental unit of information storage
- OS uses storage devices such as disks/tapes
- maps bytes of stream to physical positions on these devices
- UNIX operations on file: open, close, read, write, lseek, ioctl
- other resources = machine component necessary for program execution
(e.g. processor, memory, tape drive)
OS maintains descriptors for these abstractions in tables:
e.g. resource descriptor table
- identity
- state (idle, allocated)
- what process associated with it (if allocated)
- number/identity of available units
- we will look at other descriptor tables in more detail shortly
------------- FILES PRACTICE -----------
Opening/closing files in UNIX:
creat(2): #include <sys/stat.h>
int creat(char *path, mode_t mode);
/* = open(path, O_WRONLY | O_CREAT | O_TRUNC, mode) */
open(2): #include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open (char *path, int flag, [mode_t mode] );
close(2): int close (int fd);
- mode = permission bits (rwx access; optional)
- flag is one of the following:
- O_RDONLY, O_WRONLY, O_RDWR
- possibly bitwise OR'd with one or more of:
- O_APPEND, O_CREAT, O_EXECL, O_TRUNC,...
File I/O:
read(2): ssize_t read (int fildes, void *buf, size_t nbytes);
write(2): ssize_t write (int fildes, void *buf, size_t nbytes);
lseek(2): #include <sys/types.h>
#include <unistd.h>
off_t lseek(int fildes, off_t offset, int whence);
- whence is one of the following:
- SEEK_SET, SEEK_CUR, SEEK_END
- perform arbitrary control requests, eg. set file nonblocking
ioctl(2): int ioctl(int fd, int request, caddr_t arg);
Note: file operations used as abstraction for other resources