What does an Operating System Do? Manages Resources processes compete for CPU, memory, ... can’t leave sharing to individual programs (why?) protection Provides services Abstraction (hiding detail) e.g.: filestore, not disk drive (geometry, capacity, etc) variable size stack (hide memory shuffling, etc) reliable network connection (not sumchecks, retries) 01/01/2019 CS2051 Lecture 2
Processes Process: A program in execution Process != Program Why? (simplicity, speed; think of the real world!) eg, time-sharing, multiprogramming (!=multiprocessing) Thread: (process = thread + address space) sequence of instructions in a sequential execution context multithreading (what if two threads run a++ concurrently?) process & thread? multiple threads per address space more later on! See Bacon, Chapter 4. 01/01/2019 CS2051 Lecture 2
Example a.out 7 results in 7 - 0X80495a8 Int x; main(int argc, char *argv[]) { x=atoi(argv[1]); while (1) printf(“%d - 0X%x \n”, x, &x); } a.out 7 results in 7 - 0X80495a8 Different programs have the illusion that they use the same address! 01/01/2019 CS2051 Lecture 2
OS provides “Virtual Machine” More convenient abstraction than real machine (cf. with Java Virtual Machine) User Application Filestore CPU Network 4 Gbyte memory Yahoo.com User Application Filestore CPU Network 4 Gbyte memory Yahoo.com User Application Filestore CPU Network 4 Gbyte memory Yahoo.com User Application Network 4 Gbyte memory Filestore CPU 01/01/2019 CS2051 Lecture 2 Yahoo.com
Virtual Machine enforces Protection System against Program Buggy (or malicious?) program cannot prejudice OS Program against Program Buggy program cannot interfere with other program what if: while(1) fork(); 01/01/2019 CS2051 Lecture 2
OS Services Provided E.g. User types “run myprog” (“% myprog” in Unix) Read command (command interpreter - shell in Unix) Find program file (how big?) Allocate memory Read file into memory Find libraries Start myprog running Finish “clearly” 01/01/2019 CS2051 Lecture 2
Privileged Operations OS/Hardware prevent unprivileged software from directly accessing facilities which may affect more than one program file operations disk I/O memory allocation CPU allocation Network operations 01/01/2019 CS2051 Lecture 2
Network Device Manager OS Structure Application Operating System File Manager Memory Manager Process Manager Network Manager Device Manager Network Device Manager 01/01/2019 CS2051 Lecture 2
System Calls vs System Programs Interface between a running program and the OS. Eg: read(int fd, char *buf, int num_bytes); not to be confused with the library function: fread(void *ptr, size_t size, size_t n, FILE *stream); not all languages allow system calls to be made directly System programs provide a convenient environment for program development/execution (eg, file manipulation, status, etc…); most users’ view of the OS! 01/01/2019 CS2051 Lecture 2
Don’t always need all modules... e.g. Network Gateway Network B Network A Gateway 01/01/2019 CS2051 Lecture 2
But… Big OS Kernels have problems... Microkernels Size: (1.8Mb for Sun; 1.2Mb for Linux) Internal Complexity Debugging Microkernels tailored for special-purpose applications easier to maintain, tune, debug mK and services real-time(?) 01/01/2019 CS2051 Lecture 2
In Summary... Operating System Components: Process Management Memory Management File Management I/O Management Secondary Storage Management Network Management Command Interpreter/GUI Protection Read Bacon, 2.1-2.5; try the exercises at the end of the chapter. 01/01/2019 CS2051 Lecture 2