Basic Concepts
Policy: time-sharing (context switch) + scheduling
jobs (for batch), user programs or tasks (for time-shared systems)
Process: a program in execution
Parts: text section, program counter, stack, data section, heap
Program is passive, process is active (program becomes process when loaded)
States: new, running, waiting, ready, terminated
PCB: data structure for process, track the state of process
Executing and Switching
Direct Execution: we need protection (dual mode and system call) and time sharing (context switch)
Limited Direct Execution:
OS: create entry
OS: allocate memory, load program, set up stack
OS: fill kernel stack
return from trap, move to user mode
Program: run main()
Program: call system call
Hardware: save regs to kernel stack
Hardware: move to kernel mode, jump to handler
OS: handle trap
return from trap
restore regs from kernel stack
move to user mode
jump to PC after trap
...
Time-sharing: switch between processes, via timer interrupt
Proc A
H: timer interrupt
H: save regsA to kstackA
H: move to kernel mode
H: jump to timer handler
OS: save regsA to PCBA
OS: restore regsB from PCBB
OS: switch to kstackB
H: restore regsB from kstackB
...
Proc B
Reg saves/restores
timer interrupt: user regs are implicitly saved by hardware into kstack
**os switch: kernel **regs are explicitly saved by OS into PCB
Scheduling
scheduling: job queue, ready queue, device queues
CPU scheduler, job shceduler, medium-term scheduler
Operations
Parent process create children, form a tree, pid
Child duplicate address space of parent, may has a program loaded into it
fork()
creates new process, and exec()
replace memory space with a new program, abort()
to terminate
cascading termination: all succ are terminated
wait()
to wait it finish, no parent waiting as zombie, parent terminated without wait and then become orphan
InterProcess Communication
Shared memory: under control of user processes, not os
Message Passing: send
and receive
, blocking/non-blocking
MP is useful for small ones, easier to implement in distributed system
SM is faster (less use of syscall), but SM suffers from cache coherency, so in multiprocessor system, MP may be better
now MP is preferred
etc
socket: endpoint for communication
RPC: abstracts procedure calls betweeen processes on network systems
Pipes: a buffer, ordinary/named