Operating Systems Course Outline
3. Processes
- process composition
- value of program counter, register values, stack of temporory data like
(function params and values), data section (globals), heap (dynamically allocated memory), program code (code section).
- process states
- new, running, waiting(waiting for an event to occur), ready (waiting to get CPU), terminated (zombie).
- process control block (PCB)
- represents process in OS. contains: process state, program counter, CPU registers (ex.
accumulators), process priority, memory location, stats on the process, list of I/O assigned to process, info on threads.
- process scheduling
- on multiprocess machines, the goal is have some process running at all times. Uses a
scheduling queue
- Job queue
- all processes on system.
- ready queue
- processes (PCB) in memory and waiting to execute
- device queue
- list of processes waiting for a particular device (I/O) . The device may be busy executing something from another process.
- queueing diagram
- show an example of one. Page 108
- dispatching
- selecting a process for execution.
- I/O Bound
- process which spends most of its time doing I/O
- CPU Bound
- process which spends most of its time doing computations
- scheduler
- OS element that determines which process gets the CPU next.
There is a short term scheduler and a longer term one. Logterm has more time
to decide which processes to make ready.
Long term Scheduler should pick a mix of CPU and I/O bound processes to make ready.
Windows and UNIX have no longterm scheduler. All processes are made ready for the short term scheduler to access.
- swapping
- when the medium term scheduler decided to temporarily remove
one process from memory and from the ready queue, to lighten the load for
other processes.
- Context
- PCB (CPU register values,process state,memory locations)
- context switch
- storing the context of a process so another
process can be run. State save and state restore. Takes a few milliseconds, but takes longer for a more complex OS.
- Process creating
- Parent forks child and so on. Parent gets PID of child. init
Child's resources may be a subset of the parent's or may be external, provided by the OS.
Parent can pass data to child at initialization, eg. a file name to be opened.
Parent may stop running until child(ren) finish, or it may run concurrently.
Child might run an exec command , thus replacing his memory image.
- UNIX fork
- returns 0 to child process and CPID to parent process. Parent variables
are recreated in child and both processes continue executing from point after the fork. Show code example.
- process termination
- child runs exit() to end and OS deallocated all system resourced.
Exit value is returned to parent. Parent can allso "kill" child using the CPID and kill(). In
UNIX if a parent dies before child, init become the new parent. Parent can pause by wait()ing
for a child to terminate. It can also waitpid() for a specific child. If parent does not wait
and a child dies, it becomes a "zombie" and the OS stores its exit value for any future wait.
- Inter Process Communication (IPC)
- processes can be totally independent if they have no way to affect each other.
If they are intended to work together they must communicate either via (1)shared memory or (2) Message passing.
- pros and cons of message passing and shared memeory
-
MP better for small data transfer, no mutex needed. MP is easier than SM when
you need intercomputer communication. SM requires only a one time system call,
unlike MP. It is faster than MP but requires mutex/semaphore.
- Creating SM
- system call to get memory, then each must attach to it.
Need to prevent simultaneous accessing.
- Producer-Consumer
- produces info, uses info. Web server - browser.
Compiler - assembler. Both could access one buffer. Need to maintain
pointers to know when full or empty. (bounded and unbounded buffers).
Also need mutex/semaphore to prevent simultaneous accessing.
- Message Passing Addressing
- You can either send to/
receive from a specific process
or to a port/mailbox. The latter scheme is more versatile since any process
may then communicate with you, via the port.
- MP Blocking
- If either side (sender or receiver) waits for message to
be accepted by the other side before sending more, we call that blocking.
MP can be blocked on one side , or both, or neither side. Also called
asynchronous and synchronous MP.
- buffering
- the OS must buffer messages for the processes if the sender is non-blocking.
- Show example of Shared Memory
- See my unix lab website
- Sockets
- end-point of communication. 65,535 on a PC. Well Known
ports, TCP (COP) UDP (CLOP). Client initiates connection, uses IP.
- Remote Procedure Calls (RPC)
-
Use a specific port on another machine (server) to execute an associated
command. More structured than sockets. Need to deal with network packet
duplications to achieve "exactly once" command execution. First implement
"at most once" by sending timestamps and storing a history in the server. Repeated commands are thrown out. Then use ACKs sent from the server to verify
that the command reached the server. Client resends until he gets and ACK.
- pipe
- system resource
designed to allow communication between processes on one computer.
- ordinary pipe (or "anonymous pipes" in Windows)
- A pipe which allow producer consumer communication. One side write, other side reads, unidirectional. A second pipe would be needed for reverse communication. Unix use read() and write() commands like files. Used in Parent-child process relationships.
Examples are in the Unix Lab. Non reading process should close its reading side of the pipe. Non writing side of the pipe should close its writing side of the pipe.
- Named pipes
- bi-directional pipes that exist independently of other processes. Many processes can use them simultaneously. In UNIX they are called FIFOs , mkfifo(), and are half-duplex. In Windows named pipes are full
duplex and can allow intercomputer communication.
© Nachum Danzig 2010