Operating Systems and Systems Integration

Tutorial: Process Control Blocks — Solutions

1. What is a process control block (pcb)?

A process control block is a data structure used by an operating system to manage processes.

2. Is a pcb only found in a Linux or posix os or is it found in all operating systems?

As I mentioned in the notes, process control blocks are found in all modern operating systems. The structure of pcbs will be different on each operating system though.

3. Give ONE other name for a pcb.

It is sometimes called a process descriptor, or a task descriptor. In the 2.6 source code of Linux, the data type is a structure called task struct

4. Give ONE name for the data structure that holds the pcbs.

The process table. The pcbs may be put into a number of lists at the same time. The process table describes the system by which the operating system finds a pcb by its process id.

5. Briefly define the term program counter.

The program counter is a cpu register that holds the address of the next instruction that will be fetched. As the cpu fetches each instruction, the pc is automatically incremented to point to the next instruction. You might like to play with the simple Macromedia Flash model of a simple computer consisting of a cpu and ram connected by a 4-bit data bus, 3-bit address bus, and 2-line control bus. You can find it at http://ictlab.tyict.vtc.edu.

hk/ossi/lectures/processes/fetching.swf. The ram contains three instruc-

tions, each occupies two 4-bit memory locations.

6. What data is held in the program counter?

The address of the next machine instruction that will be fetched and executed.

Process Control Blocks: In figure 1 on the following page we see three processes, P1, P2 and P3. There are seven moments in time where the main values of the pcbs of the three processes are shown. The time intervals are not equal; they are just where the scheduler changed the process. The size of all i^{/}o instructions is three bytes. In each pcb I have shown the program counter value, and the process state. The process state can be running (i.e., executing on the cpu), ready (i.e., ready to run), and sleeping (i.e., blocked). There are two queues shown: a wait queue for processes that are blocked waiting for i^{/}o, and a ready queue, for processes that are in the ready to run state.

Tutorial: Process Control Blocks Operating Systems and Systems Integration Solutions

2

Figure 1: An example of three processes executing, showing their process control blocks.

1. State the technical term for what the scheduler does at each of the times t_{0}, t_{1}, t_{2}, t_{3}, t_{4}, t_{5} and t_{6}.

Context switch.

2. Does process P1 perform i^{/}o? If so, at what address is the i^{/}o instruction?

Yes, you can see that it does, because the state of that process is sleeping after t_{1}, and you can see that it appears in the wait queue, where it waits for the input or output to finish. We are told that the i^{/}o instructions are three bytes long in this particular example, as specified in the question. At t_{1}, the cpu has already executed the i^{/}o instruction. This is what caused the os to put the process onto the wait queue, since i^{/}o devices are typically much slower than the rate at which the cpu can execute instructions. The os put the process into the sleeping state when the program counter was pointing to the next instruction to be fetched that comes immediately after the i^{/}o instruction. So we know that the address of the instruction after the i^{/}o instruction is at address C0DE_{16}. The size of the i^{/}o instruction is three bytes, i.e., it is three address locations before C0DE_{16}, so its address is C0DE_{16} − 3 = C0DB_{16}.

3. Does process P2 perform i^{/}o? If so, at what address is the i^{/}o instruction?

Yes, we can see that P2 moves to the sleeping state at time t_{2}, where we see that it is also on the wait queue. Using the same reasoning as before, we can see that the address of the i^{/}o instruction is FEED_{16} − 3 = FEEA_{16}.

Tutorial: Process Control Blocks Operating Systems and Systems Integration Solutions

3

4. Does process P3 perform i^{/}o? If so, at what address is the i^{/}o instruction? Yes, P3 is blocked for i^{/}o at time t_{3}. The address of the i^{/}o instruction is D1CE_{16}− 3 = D1CB_{16}.

5. List at least FIVE other kinds of data that will be stored in a pcb that is not shown in figure 1 on the previous page. If you look at the definition of the data type task struct in the header file /usr/

src/linux-2.4.22-1.2188.nptl/include/linux/sched.h and also see the def-
inition of thread struct in /usr/src/linux-2.4.22-1.2188.nptl/include/

asm/processor.h, you will see that the pcb contains a great deal of information about the process, including:

• The process id

• the process state (for example, whether it is executing, ready to run, or sleeping)

• program counter (stored in thread struct)

• the scheduling priority

• information about the user and groups associated with this process

• pointer to the parent process pcb

• pointer to a list of child process pcbs

• pointers to the process’s data and machine code in memory

• pointers to open files and other resources held by the process