Lecture 3 - Processes Flashcards
Can we associate a FIFO to more than two processes?
Yes.
Process
A program in execution; process execution must progress in sequential fashion
Program becomes process when executable file loaded into memory.
One program can have multiple processes.
5 parts of process
- Text section (program code)
- Current activity (program counter), processor registers
- Stack containing temporary data (function parameters, return addresses, local variables)
- Data section: global variables (initialized and unitialized)
- Heap: memory dynamically allocated during run time
5 states of process
- New: The process is being created
- Running: Instructions are being executed
- Waiting: The process is waiting for some event to occur
- Ready: The process is waiting to be assigned to a processor
- Terminated: The process has finished execution
Process Control Block (PCB)
Hold information associated with each process:
■Process state –running, waiting, etc
■Program counter –location of instruction to next execute
■CPU registers –contents of all process-centric registers
■CPU scheduling information-priorities, scheduling queue pointers
■Memory-management information –memory allocated to the process
■Accounting information –CPU used, clock time elapsed since start, time limits
■I/O status information –I/O devices allocated to process, list of open files
Threads
Ability to run multiple processes within one program by having multiple program counters executing multiple locations at once. Need to store thread details in PCB.
C structure to represent Process in Linux
task_struct:
pid t_pid; /* process identifier /
long state; / state of the process /
unsigned int time_slice / scheduling information */
struct task_struct parent;/ this process’s parent /
struct list_head children; / this process’s children */
struct files_struct files;/ list of open files */
struct mm_struct mm; / address space of this process */
Main benefit of Process Scheduling
Maximize CPU use, quickly switch processes onto CPU core
Role of Process Scheduler
Process scheduler selects among available processes for next execution on CPU core
2 Scheduling Queues of processes
- Ready queue –set of all processes residing in main memory, ready and waiting to execute
- Wait queues –set of processes waiting for an event (i.e. I/O)
CPU Context switch
When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process
Context of a process
Current state of process, represented in PCB
What is context-switch overhead?
When the cpu switches between contexts, it does no useful work. The more complex the OS and the PCB, the longer the context switch.
Why does context switch depend on hardware?
We could have cpus with multiple sets of registers, which allows multiople contexts to be loaded at once. Faster.
Main difference between multitasking in IOS vs Android?
IOS is more limited on the background processes it can run, and has one main foreground process.
Android has both, but background processes uses a service to perform tasks, which can run even if background is suspended. The service has no ui and small memory use, which allows it to do more.
2 main process operations
- Creation
2. Termination
process identifier (pid)
id assigned to a created process
How does a tree of processes occur?
Parent creates children, which in turn can create other children
3 Resource sharing options between Parent and Child process
- Parent and children share all resources
- Children share subset of parent’s resources
- Parent and child share no resources
2 Execution options between Parent and Child process
- Parent and child can run concurrently
2. Parent waits for child to terminate
Relationship between child and parent address space
Child duplicate of parent virtual address space, and changes in one don’t affect the other.
fork() system call
creates child process (pid = 0) from parent process (pid > 0)