Process
the process is the OS abstraction for a running program
controlled by Process Control Block(PCB), has all info about the process, heavyweight
Process components
- every state the process needs
- memory address space
- code and data for the program
- stack
- PC
- registers
- OS resources
- nmaed by its process ID (PID)
Process state
- new: process is being created
- ready: process is waiting to be assigned to a processor
- running: instructions are being executed
- waiting (blocked): process is waiting for some event to occur (eg: I/O completion)
Process Life Cycle
Creation
- every process is created by another process, the creating process is called parent and the created process is called child.
- view by
pstree, create byBOOL CreateProcess(char *programName, char *args[])on Windows,int fork(),int exec(char *prog, char *argv[])on UnixCreateProcess: create/init PCB, load program byprogramName, copy and giveargs[]to the program, and then add it to the ready queuefork: copy the PCB of the parent, copy entire contents of address space of parent, and initiailize kernal resources to point to resource used by parent, and then initialize hardware context to be copy of the parents.exec: stops the current process, load and initialize the new program, then set ready (DOES NOT CREATE NEW PROCESS)

fork vs CreateProcess
forkis copy of the parent,CreateProcessis load a new programforkreturn 0 to the child process, and return the child PID to the parent process, therefore,fork() == 0indicate this is a child process

Termination
ExitProcess(int status)on Windows,exit(int status)on Unix- close open files, connections, release memory BY OS, not the process itself
waiting
wait()on Unix, which suspend current process until any child process terminateswaitpid(int pid)on Unix, which suspend current process until the child process withpidterminates
Questions
how many processes are created when program runs?
- 3 processes are created, 1 parent and 2 children
- however, only 1 or 2 active processes. we dont know if the second process is exited or not.