OS Structure Processes Vivek Pai COS 318 September
OS Structure & Processes Vivek Pai COS 318 September 19, 2002 OS Structure & Processes 1
Foodundgedank n n n You’re the host/hostess of a banquet hall that has accidentally been double-booked. It has three rooms – the large dining room, the cocktail room, and a small buffet line room. If each guest is given a card with the room layout with table numbers, and the guest’s own table number, how can you solve this problem? What issues are involved regarding the sizes of the two groups? OS Structure & Processes 2
Administrative n First precept happened, more to come – Friday’s booked – same time, same place Yong is this project’s TA n Project 1 due 11: 59 pm Oct 1 n Almost everyone has given me details n – Get me what remains n Next reading assignment: ? ? ? OS Structure & Processes 3
A Friendly Deception Hiding information n Giving out different information while appearing to be the same n Stalling when necessary n Drawback? Maybe lots of extra work n Benefit: makes life easier for user n OS Structure & Processes 4
Host/Hostess Problem n Each group < 50% – Have two sets of cards with different numbering schemes n Each group slightly above 50% – Slow down the buffet line & entrance n Each group near 100% – One group in dining room, other in cocktail room OS Structure & Processes 5
Users, Programs, Processes Users have accounts on the system n Users launch programs n – Many users may launch same program – One user may launch many instances of the same program n Processes are instances of a program – The “program” can really be a set of processes OS Structure & Processes 6
Programs As Process Collections n Netscape (output of “ps x”) – 7253 p 0 S – 7280 p 0 I n 0: 19. 26 /usr/local/lib/netscape/communicator-4. 75. bin -irix-s 0: 00. 15 (dns helper) (communicator-4. 7) gcc (via “gcc –pipe –v”) – /usr/libexec/cpp | – /usr/libexec/cc 1 | – /usr/libexec/as, followed by – /usr/libexec/elf/ld OS Structure & Processes 7
gcc example You launch gcc n It first launches cpp, cc 1, as n It then launches ld n n Each instance is a process, and each program actually exists separately – You could launch cc 1 manually if you wanted OS Structure & Processes 8
So What Is A Process? It’s one instance of a “program” n It’s separate from other instances n It can start (“launch”) other processes n It can be launched by them n OS Structure & Processes 9
What Does This Program Do? int myval; int main(int argc, char *argv[]) { myval = atoi(argv[1]); while (1) printf(“myval is %d, loc 0 x%lxn”, myval, (long) &myval); } OS Structure & Processes 10
Here’s The Output OS Structure & Processes 11
Instances Of Programs The address was always the same n The values were different n – Implies that the programs aren’t seeing each other – But they think they’re using the same address Conclusion: addresses are not absolute n What’s the benefit? n OS Structure & Processes 12
So What’s In A Process? n Information about the hierarchy – What launched it – What it has launched n Information about resources – Where is it storing data – What other resources it’s using n Various kinds of mappings OS Structure & Processes 13
Consider How To Read a File n Compare read( ) and fread( ) n read(int d, void *buf, size_t nbytes) read( ) attempts to read nbytes of data from the object referenced by the descriptor d into the buffer pointed to by buf. n fread(void *ptr, size_t size, size_t nmemb, FILE *stream) The function fread( ) reads nmemb objects, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr. OS Structure & Processes 14
Which is a System Call and Why n n read(int d, void *buf, size_t nbytes) fread(void *ptr, size_t size, size_t nmemb, FILE *stream) Both do the same thing, right? n What gets “exposed” in each case n What about a lying programmer n – How hard is it to tell he/she is lying – What other malicious actions can occur? OS Structure & Processes 15
What State Is Implied? n Consider the following sequence: read(int d, void *buf, size_t nbytes) What happens if two programs were doing this? OS Structure & Processes 16
Some Insight Into OS Array of File Pointers Process Actual File Info What do we gain from this? OS Structure & Processes 17
Some Insight Into OS Array of File Pointers Process Actual File Info Process OS Structure & Processes 18
Examining Those Other Parameters n n read(int d, void *buf, size_t nbytes) fread(void *ptr, size_t size, size_t nmemb, FILE *stream) Where is [buf, buf+nbytes)? Where is [ptr, ptr+size*nmemb)? OS Structure & Processes 19
Remember This? Application Libraries User space/level Kernel space/level Portable OS Layer Machine-dependent layer OS Structure & Processes 20
Address Space n One (common) approach – Kernel is high memory – User is low memory n What restrictions apply? n read(f, buf, nbytes) OS Structure & Processes 0 xffff…. Kernel space User space 0 x 0000… 21
Some Definitions n Kernel – “heart” of the operating system – Like the program file generated by compiling all of the operating system files n Operating system – usually includes more – Various libraries – Support programs n Hard and fast definitions? Rarely OS Structure & Processes 22
More Address Space n Program segments – Text – Data – Stack – Heap n Any obvious choices? OS Structure & Processes 0 xffff…. Kernel space User space 0 x 0000… 23
One Common Layout n Lots of flexibility – Allows stack growth – Allows heap growth – No predetermined division n 0 xffff…. Kernel space Stack So what happens when you make a system call? OS Structure & Processes Heap Code & Data 0 x 0000… 24
Kernel Stack n Kernel contains functions – Just like regular functions – Automatic variables, formal parameters, etc – They need a stack n Can we use the user’s stack? – Is it possible? – Is it desirable? OS Structure & Processes 25
Is The Kernel A Process? n Monolithic OS – Most forms of OS you’ve probably used n Layered systems – THE system (design) – Multics (design + hardware support) Hypervisors/virtual machines n Client/Server (microkernels) n – Mach OS Structure & Processes 26
What Other Options Possible? n Remember the host/hostess scenario? – What would happen if you had a break between courses – Can you apply this logic to the kernel? – What are the tradeoffs? OS Structure & Processes 27
- Slides: 27