Week 11 - Linux Processes Flashcards

1
Q

Program

A

Executable code, or source code
- Static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Process

A

is a running program
- Active
- Can be started by a GUI, command line or by another process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

2 types of processes

A

Foreground process - interacts with user

Background process - runs to completion and report results (to file or window)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Process consists of

A
  • Set of executable instructions
  • Region of memory which stores:
  • Executable instructions
  • Process specific data (values in variables)
  • Call Stack
  • Operating System resources
  • File descriptors
  • Security attributes
  • Process owner & permissions
  • Processor State
  • Content of CPU registers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Process ID

A

When a process runs, Linux keeps track of it
through a process ID (PID)
* When linux boots, the first process created is an initialization process call systemd (or init )
* Systemd is given PID = 1
* Each new process gets next available PID
* If your computer hasn’t been rebooted in a while, the PIDs could be in tens of thousands
* Each process also has a Parent PID
* PID of the process which created it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Process creation

A

Process can only be created by another process
* Parent Process creates (spawns) one or more child processes

System calls are used to create process
a system call is function call to Linux Kernel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Process creation

A

Process can only be created by another process
* Parent Process creates (spawns) one or more child processes
* System Call = Function call to Linux Kernel
* To create a process, System call is required
* fork()
* exec()
* wait()
* vfork

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Process consists of

A

Region of memory which includes executable instructions and process specific data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Fork

A

Duplicates Parent process to create child

Creates new region of memory, and duplicates contents of memory
* E.g Process A creates process B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Wait

A
  • Wait system call is same as fork with one key difference
  • The parent goes into a wait state (sleep) until the child terminates

Duplicates parent process to create child

Parent sleeps until child terminates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Exec

A

Exec system call causes a process to start a new program which replaces the current process.

In other words, creates a new process which replaces the current process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

vfork

A

operates in the same way as fork, with one exception

The parent and the child share the same memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

fork + exec

A

Typical usage of exec is to pair it with fork
1. Parent calls fork to create a new process with a new PID
* New process is a duplicate of the parent

  1. The child then calls exec to change the process to execute a different program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a computer? CPU

A
  • The processor (central processing unit, CPU)
  • Performs the fetch
    execute cycle
  1. Fetch next program instruction from memory
  2. Decode the instruction into actions
  3. Command the relevant part(s) of the computer to operate to
    execute the instruction
  4. Store the result somewhere (if necessary)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The CPU consists of

A

Control Unit
* Handles the fetch
execute cycle
* Controls the other components of the computer through signals
* Contains registers (storage locations) for important pieces of
information like the memory location of the next instruction in the
program and the current instruction

  • Arithmetic Logic Unit (ALU)
  • Digital circuits to perform arithmetic and logic operations
  • Data registers to store data being used by the current set of
    instructions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a computer? CPU

A

Consider an example:
* We write the instruction A = B * (C + D)
* This is broken into several lesser machine code instructions
* Load C into a data register
* Add D to the data register storing C
* Multiply B to the data register storing C + D
* Store result in A

17
Q

Explain what happens as process executes

A

The state of the process changes
* Variables change values
* Portions of program move from swap space to memory
* CPU Registers Change
* Current instruction changes (IP)
* Instruction that the processor will execute next changes (PC)
* Status flags change

18
Q

As a process executes, state of the process changes

A
  • OS must keep track of state of process
  • Does so using
    Process Status Word (
  • PSW is a collection of most important pieces of info about a process
  • Current values of CPU registers
  • In other words, PSW store’s a snapshot of the process
19
Q

Process Management

A
  • OS must also schedule when a process executes
  • Scheduling of processes is known as process management

Process management has evolved over the years from single process execution to concurrent processing.

20
Q

Single Process Execution

A

Single Tasking
* OS starts a process
* CPU operates on just this process
* Computer thus only run one process at a time
* Process must terminate (or suspended by user) before another
process can be executed.

21
Q

Single Process Execution

BATCH

A
  • Sequence of processes
  • Each process runs one at a time
  • OS schedules which processes is executed next
  • First in First out
  • Priority
  • Shortest first
  • Processes cannot be interactive (offline)

Batch does not get efficient use from CPU
* E.g. process is running, and needs to read from disk
* Process must wait for slow disk to return data
* When process is waiting, CPU is sitting idle

22
Q

Concurrent Processing

A
  • Idea is to maximize use of CPU
  • Don’t let CPU sit idle

Multi programming
* When a process is performing time
consuming I/O,
process is removed from CPU and replaced with a
different process.
* Looks as if more that one process is executing at the same time
* Replacement of Process is called
Context Switch

23
Q

Context switch

A
  • Switching of processes on the CPU
  • Current Process replaced by next process
  • OS must first store the state of the current process
  • Process State Word (PSW) Stores state of process
  • PSW of current process read from CPU & stored in OS memory
  • PSW of new process is loaded from memory & loaded onto CPU
  • Once context switch happens, CPU resumes and executes new process
24
Q

Multi-tasking

A
  • Similar to Multi
    Programming (context switch happens)
  • In Multi
    Programming: Context switch occurs when process does slow I/O operation
  • In Multi
    Tasking: Context switch occurs after a set amount of time (also when slow I/O occurs)
  • CPU has a timer
  • Timer set to a threshold ( e.g 10,000)
  • Process is executed, timer is reduced at each clock tick
  • When timer reaches 0: Context switch occurs and new process
    loaded to CPU
  • In other words: each process takes turns using CPU.
  • Each process only has set amount of time on CPU before another
    process gets to use CPU.
25
Q

Multi-processing

A
  • Multiple CPUs (Multi Core)
  • OS selects which CPU (Core) will execute a particular processor
  • Each individual processor performs multi tasking
26
Q

Monitoring processes

A
  • You may need to see what a process is doing
  • Process could be using too much resources
  • Helps understand processes more

top
* Provides ongoing look at the processor activity in real time
* Displays PID, CPU usage, Memory usage, owner etc
* Updates every 3 seconds (default)

vmstat
Displays summary information about OS memory and processes, context switches and block I/O

27
Q

CPU Can only execute one process at a time

A

Single tasking
Batch
Multi-programming
Multi-tasking