What are processes vs programs? - A program in action - Processes cannot just be "created", must be cloned - Usually OS starts first process known as "init" - The OS keeps track of all parent, child, sibling relationships - Run pstree to get this info - What do they have associated with them? - pid -> global - file descriptors -> local - VM mapping - State -> Running, waiting, stopped, zombie - Scheduling - Processor "context" How to clone processes? Look at fork examples: - Simple refresher - What is actually inherited? - new pid - file descriptors are the same - Context is the same - VM is copied What is IPC? - We want to talk to another process, what do? - Kernel gives us a few options including: - FIFO, Pipe, Shared Memory, Signals - Sockets when we start networking Look at fifo example - Stored on disk - Has to be opened at both ends simultaneously Look at pipe example - Requires common parent process - Has atomicity guarantees - How might you implement bash pipe operator? "|" - redirection using dup2 Look at signals: - Software interrupts (as opposed to hardware ones) - Can be ignored, caught, or let the default action occur - Some cannot be changed or ignored (SIGKILL) - On exec() signals reset Look at shared memory: - Draw diagram of shared memory - What else can mmap be used for? What do you need to do for ex04? - Write a shell - Replaces stdin of command with fd from environment variable How? - getenv("USTDIN") - command loop -> readline - fork - In child, open file from env var - Use dup2 to replace stdin - Use execl - In parent, wait for child