Lecture 3 - Processes Flashcards

1
Q

Can we associate a FIFO to more than two processes?

A

Yes.

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

Process

A

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.

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

5 parts of process

A
  1. Text section (program code)
  2. Current activity (program counter), processor registers
  3. Stack containing temporary data (function parameters, return addresses, local variables)
  4. Data section: global variables (initialized and unitialized)
  5. Heap: memory dynamically allocated during run time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

5 states of process

A
  1. New: The process is being created
  2. Running: Instructions are being executed
  3. Waiting: The process is waiting for some event to occur
  4. Ready: The process is waiting to be assigned to a processor
  5. Terminated: The process has finished execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Process Control Block (PCB)

A

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

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

Threads

A

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.

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

C structure to represent Process in Linux

A

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 */

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

Main benefit of Process Scheduling

A

Maximize CPU use, quickly switch processes onto CPU core

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

Role of Process Scheduler

A

Process scheduler selects among available processes for next execution on CPU core

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

2 Scheduling Queues of processes

A
  1. Ready queue –set of all processes residing in main memory, ready and waiting to execute
  2. Wait queues –set of processes waiting for an event (i.e. I/O)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

CPU Context switch

A

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

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

Context of a process

A

Current state of process, represented in PCB

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

What is context-switch overhead?

A

When the cpu switches between contexts, it does no useful work. The more complex the OS and the PCB, the longer the context switch.

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

Why does context switch depend on hardware?

A

We could have cpus with multiple sets of registers, which allows multiople contexts to be loaded at once. Faster.

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

Main difference between multitasking in IOS vs Android?

A

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.

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

2 main process operations

A
  1. Creation

2. Termination

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

process identifier (pid)

A

id assigned to a created process

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

How does a tree of processes occur?

A

Parent creates children, which in turn can create other children

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

3 Resource sharing options between Parent and Child process

A
  1. Parent and children share all resources
  2. Children share subset of parent’s resources
  3. Parent and child share no resources
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

2 Execution options between Parent and Child process

A
  1. Parent and child can run concurrently

2. Parent waits for child to terminate

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

Relationship between child and parent address space

A

Child duplicate of parent virtual address space, and changes in one don’t affect the other.

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

fork() system call

A

creates child process (pid = 0) from parent process (pid > 0)

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

exec() system call

A

replace the process’memory space with a new program

24
Q

wait() system call

A

The parent process may wait for termination of a child process by using the wait()system call. The call returns status information and the pid of the terminated process
pid = wait(&status);

25
Q

What happens when a process terminate?

A

Asks the operating system to delete it using the exit() system call.
● Returns status data from child to parent (via wait())
● Process’resources are deallocated by operating system

26
Q

abort() function

+ 3 reasons to use it

A

Parent may terminate the execution of children processes using the abort() system call:

  1. Child has exceeded allocated resources.
  2. Task assigned to child is no longer required.
  3. The parent is exiting and the operating systems does not allow a child to continue if its parent terminates.
27
Q

Cascading (process) termination

A

Some operating systems do not allow child to exists if its parent has terminated. If a process terminates, then all its children must also be terminated.

28
Q

zombie process

A

If no parent waiting (did not invoke wait()) process is a zombie

29
Q

orphan process

A

If parent terminated without invoking wait(), process is an orphan

30
Q

Android Process Importance Hierarchy

A
Foreground process
Visible process
Service process
Background process
Empty process
31
Q

Problem with running web browser as single process

A

If one web site causes trouble, entire browser can hang or crash

32
Q

Cooperating process

+ 4 reasons

A
Can affect or be affected by other processes, including sharing data:
●Information sharing
●Computation speedup
●Modularity
●Convenience
33
Q
Interprocess communication (IPC)
\+ 2 Models
A

Method by which processes cooperate:

  1. Shared memory (same memory block)
  2. Memory passing (through message queue)
34
Q

Independent Process

A

Cannot affect or be affected by the execution of another process

35
Q

unbounded-buffer

A

Places no practical limit on the size of the buffer between producer and consumer

36
Q

bounded-buffer

A

Assumes that there is a fixed buffer size between producer and consumer

37
Q
Shared Memory (Interprocess Communication)
\+ Major issue
A

An area of memory shared among the processes that wish to communicate. The communication is under the control of the users processes not the operating system.

Major issues is to provide mechanism that will allow the user processes to synchronize their actions when they access shared memory.

38
Q

Message Passing

A

Mechanism for processes to communicate and to synchronize their actions.
Message system –processes communicate with each other without resorting to shared variables.

39
Q
  1. IPC functions for Message passing
A

●send(message)

●receive(message)

40
Q

Communication link

A

Connection between process P and Q in message passing

41
Q

Is the size of a message that the link can accommodate fixed or variable?

A

either fixed or varible

42
Q

Implementation of communication link (Message Passing):
3 Physical
3 Logical

A

Physical
• Shared memory
• Hardware bus
• Network

Logical
• Direct or indirect
• Synchronous or asynchronous
• Automatic or explicit buffering

43
Q

Direct Communication

+ 4 Properties

A

Processes must name each other explicitly:
●send(P, message) –send a message to process P
●receive(Q, message) –receive a message from process Q

Properties
●Links are established automatically
●A link is associated with exactly one pair of communicating processes
●Between each pair there exists exactly one link
●The link may be unidirectional, but is usually bi-directional

44
Q

Indirect Communication

+ 4 properties

A

Messages are directed and received from mailboxes (also referred to as ports)
●Each mailbox has a unique id
●Processes can communicate only if they share a mailbox

Properties of communication link
●Link established only if processes share a common mailbox
●A link may be associated with many processes
●Each pair of processes may share several communication links
●Link may be unidirectional or bi-directional

45
Q

3 Indirect Communication Operations

+ Send and receive function arguments

A
  1. create a new mailbox (port)
  2. send and receive messages through mailbox
  3. destroy a mailbox
    Primitives are defined as:
    send(A, message) –send a message to mailbox A
    receive(A, message) –receive a message from mailbox
46
Q

Blocking (Message Passing)

+ 2 functions

A

Blocking is considered synchronous
●Blocking send –the sender is blocked until the message is received
●Blocking receive –the receiver is blocked until a message is available

47
Q

Non-blocking (Message Passing)

+ 2 functions

A

Non-blocking is considered asynchronous
●Non-blocking send–the sender sends the message and continue
●Non-blocking receive–the receiver receives:
●A valid message, or
●Null message

48
Q

Rendezvous (Message Passing Synchronization)

A

If both send and receive are blocking, we have a rendezvous

49
Q

Buffering

+ 3 Implementation methods

A
  1. Zero capacity –no messages are queued on a link.
    Sender must wait for receiver (rendezvous)
  2. Bounded capacity –finite length of n messages.
    Sender must wait if link full
  3. Unbounded capacity –infinite length.
    Sender never waits
50
Q

Function to create Shared Memory in POSIX

A

shm_fd = shm_open(name, O CREAT | O RDWR, 0666);

51
Q

Set the size of the object in POSIX Shared Memory

A

ftruncate(shm_fd, 4096);

52
Q

mmap()

A
Use mmap() to memory-map a file pointer to the shared memory object.
Reading and writing to shared memory is done by using the pointer returned by mmap().
53
Q

Pipes

A

Acts as a conduit allowing two processes to communicate

54
Q

Ordinary pipes

A

Cannot be accessed from outside the process that created it. Typically, a parent process creates a pipe and uses it to communicate with a child process that it created.
■ Producer writes to one end (the write-end of the pipe)
■Consumer reads from the other end (the read-endof the pipe)
■Ordinary pipes are therefore unidirectional
Windows calls these anonymous pipes

55
Q

Named pipes

A

Named Pipes are more powerful than ordinary pipes
■Communication is bidirectional
■No parent-child relationship is necessary between the communicating processes
■Several processes can use the named pipe for communication
■Provided on both UNIX and Windows systems