Module 2 - The process concept and IPC Flashcards

1
Q

What is meant by a process?

A

An executable loaded into memory and executing or waiting. A
process typically executes for only a short time before it either finishes or needs to perform I/O (waiting). A process is an active entity and needs resources such as CPU time, memory etc to execute.

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

A process needs at least two critical resources, name these resources.

A

Each process must be allocated a
separate process memory image and a PCB in main memory (RAM).

CPU time.

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

Name and describe the various memory segments used by a process.

A

Stack: Temporary data such as function
parameters, local variables and return
addresses.

The stack grows from high addresses
towards lower address.

Heap: Heap: Dynamically allocated (malloc) by the program during runtime.

The heap grows from low addresses
towards higher addresses.

Data: Statically (known at compile time)
global variables and data structures.

Text: The program executable machine
instructions.

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

A process can be in different states. Name and explain the purpose of each such state.

A

New: A new process, the child process is created. The new child is a copy of its parent.

Ready: A “ready” process that is residing in main memory and is awaiting execution on a CPU.

Running: A process moves into the running state when it is chosen for execution. The process’s instructions are executed by one of the CPUs (or cores) of the system. There is at most one running process per CPU or core. A process can run in either of the two modes, namely kernel mode or user mode.

Waiting: A “waiting” process that is residing in main memory and is waiting for an I/O device.

Terminated: A process may be terminated, either from the “running” state by completing its execution or by explicitly being killed.

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

Draw a diagram showing how the process states are related using directed arrows showing possible state transitions.

A

Draw it.

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

What is the purpose of the PCB?

A

The process control block (PCB) is a data
structure in the operating system kernel
containing the information needed to
manage a particular process.

In brief, the PCB serves as the repository
for any information that may vary from
process to process.

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

Give examples of data stored in the PCB.

A

Process id (PID).

Process state (new, ready, running,
waiting or terminated).

CPU Context.

I/O status information.

Memory management information.

CPU scheduling information.

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

What is the purpose of the fork system call?

A

Fork is the primary (and historically, only) method of process creation on Unix-like operating systems.

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

What do we mean with parent and child?

A

The process calling fork() is called the parent.

The new process is called the child of the parent.

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

How many times does fork return?

A

On success, fork() return twice!

On failure, fork() returns -1 in the parent.

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

What are the possible return values of fork?

A

fork() in the parent returns either pid > 0 or -1.

fork() in the child returns 0.

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

After calling fork, how can the program know if it is executing in the parent or in the child?

A

fork() returns 0 if executing in the new child
process.

fork() returns pid > 0 if executing in the
parent process. It’s the process id (pid) of the child that is returned.

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

What is the purpose of the exit system call?

A

The child uses the exit() system call to
terminate.

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

What is the purpose of the exec family of system calls?

A

In Unix-like operating systems, the exec family of system calls runs an executable file in the context of an already existing process, replacing the previous executable.

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

When calling a function or invoking a system call, normally execution will return back to the caller, possible with a return value. Is this true for the exec family of system calls?

Justify your answer.

A

When a process calls exec, all code (text) and data in the process is lost and replaced with the executable of the new program. Although all data is replaced, all open file descriptors remains open after calling exec unless explicitly set to close-on-exec.

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

What is the purpose of the wait system call?

A

The parent may use the wait() system call to
wait for the child to terminate.

The wait() system call also makes it possible for the parent to get hold of the exit status of the terminated child.

17
Q

What is the purpose of the zombie process state?

When does a process become a zombie?

A

A terminated process is said to be a zombie or defunct until the parent does wait() on the child.

Or in other words:

‣ When a process terminates all of the memory and resources associated with it are deallocated so they can be
used by other processes.

‣ However, the exit status is maintained in the PCB until the parent picks up the exit status using wait() and deletes the PCB.

18
Q

What is the purpose of signals?

A

Signals are a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems.

‣ A signal is a notification sent to a process in order to notify it of an event that occurred.

19
Q

What are the limitations of signals?

A

‣ Exceptions such as division by zero or a
segmentation violation will generate signals.

‣ Divison by zero will generate a SIGFPE signal.

‣ Segmentation violation will generate a SIGSEGV signal.

‣ If not explicitly caught, SIGFPE and SIGSEGV will cause a core dump and a program exit.

20
Q

What happens when a process receives a signal?

A

‣ When a signal is sent, the operating system interrupts the target process’s normal flow of execution to deliver the signal.

‣ If the process has previously registered a signal handler, that routine is executed. Otherwise, the default signal handler is executed.

21
Q

Explain the file descriptor concept.

A

In Unix and Unix-like computer operating systems, a file descriptor is an abstract indicator used to access a file or other input/output resource, such as a pipe or network socket.

22
Q

What is a pipe?

A

An (anonymous) pipe is a simplex first-in first-out (FIFO) communication channel that may be used for one-way interprocess communication (IPC).

23
Q

How are file descriptors used together with pipes?

A

We create read and writes end of a pipe using file descripors.

When using the pipe(pfd) system call, you create an array pfd were its elements are assigned descriptor numbers to that pipe.

This pipe object can now be accessed by any process that has the same file descriptors.

24
Q

How do we create a pipe?

What is the result of creating a pipe?

A

In Unix-like operating systems pipes are created using the pipe() system call.

‣ As a result of the pipe() system call,
a pipe object is created.

‣ A pipe is a FIFO buffer that can be
used for inter process communication
(IPC).

‣ The pipe() system call returns a
pair of file descriptors referring to the
read and write ends of the pipe.

25
Q

How can we make two processes share a pipe in a producer-consumer manner?

A

The parent can close the read descriptor to
the pipe and the child can close the write descriptor to the pipe.

Now, the parent can act as a single producer and the child as a single
consumer of data through the pipe using
the read() and write() system calls - just as if
it was a file.

26
Q

What happens if we read from an empty pipe and there are:

a) open write descriptors attached to the
pipe, or:

b) no open write descriptors attached to
the pipe?

A

a) The reader gets blocked

b) EOF returned (end of file error)

27
Q

What happens if we write to:

a) a full pipe if there are open read descriptors attached to the pipe, or:

b) a pipe with no open read descriptors attached to the pipe?

A

a) Writer blocked

b) Writer receives the SIGPIPE signal

By default, SIGPIPE causes the process to terminate.

28
Q

What is the dup2 system call doing to file descriptors?

A

The dup2() system call copies one file descriptor entry to another entry in the file descriptor table.

29
Q

How can the dup2() system call be useful?

A

The dup2() system call is used to redirect I/O.

30
Q

In C, the rand library function can be used to generate pseudorandom numbers. How is it possible for rand to return different values on consecutive calls?

A

If you want to get different sequences, you need to seed the random number generator using srand.

srand(time(0)) returns the number of seconds since the epoch (00:00:00 UTC, January 1, 1970, for POSIX systems, not counting leap seconds).

Note that this still might give repeated values if you run it twice in the same second.