CPSC 3220 - DAY 5 SEPTEMBER 7, 2017 ================================================================================ OS DESIGN --------- Can library routines run in user mode? Can OS server processes run in kernel mode? Can OS server processes run in user mode? Thin waist Each system call can be limited in functionality. Provides primitives that you can "mix and match" Portable OS Library is in user area. System call interface is in between Portable Operating System Kernel keeps kernel side safe. UNIX Case Study --------------- Creating and managing processes fork() split processes - create a copy of current process execute() change the program being run by current process wait() wait until other process is done. signal() system call to send a notification to another process Performing I/O open() open a file read() read from a file write() write to a file close() close file Communication between processes pipe() dup2() select() connect() Process ID (pid) parent process will have the pid number of child child will have a pid of 0 Can a UNIX fork() return an error? it can return an error. Can a UNIX exec() return an error? yes, it can return an error Can a UNIX wait() return immediately? no. have to wait for signals to come back Implementing a UNIX fork ------------------------ Create and initialize the process control block (PCB) in the kernel Create a new address space Initialize the address space with a copy of the entire contents of the address space of the parent Inherit the execution context of the parent (ex. any open files) Inform the scheduler that the new process is ready to run. Implementing a UNIX exec() -------------------------- Load the program into current address space Copy arguments into memory in address space Initialize the hardware context to start execution at start. ***Note that exec() does not create a new process*** Windows CreateProcess() ----------------------- Create and initialize the process control block (PCB) in the kernel Create and intitialize a new address space Load the program into address space. Copy arguments into memory in address space Initialize the hardware context to start execution at "start" Inform the scheduler that the new process is ready to run. UNIX I/O -------- Uniformity - all operations on files, I/O devices, and pipes use the same set of system calls: open(), close(), read(), write Open before use - check permissions and set up internal housekeeping. open() returns a handle (file descriptor) for use in later calls on the file. Byte-oriented interface Kernel-buffered read() and write() Explicit close() open() gives you a pointer (reference) to the file. UNIX file open() ---------------- Open the file, return file descriptor Options: -if file doesn't exist, return an error -if file doesn't exist, create file and open it -if file does exist, return an error -if file does exist, open file -if file exists but isn't empty, open and ignore previous -if file exists but isn't empty, return an error