Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program counter of a process

I thought program counter is a part of hardware. I'm confused after reading the following. Can someone clarfiy the difference?

A single-threaded process has one program counter specifying the next instruction to execute. (Threads are covered in Chapter 4.) The execution of such a process must be sequential. The CPU executes one instruction of the process after another, until the process completes. Further, at any time, one instruction at most is executed on behalf of the process. Thus, although two processes may be associated with the same program, they are nevertheless considered two separate execution sequences. A multithreaded process has multiple program counters, each pointing to the next instruction to execute for a given thread.

like image 809
mmswe Avatar asked Feb 06 '15 13:02

mmswe


People also ask

Is program counter a part to process?

As you said, the "program counter" (also called "instruction pointer") is part of the hardware; more specifically, it's a processor register. The whole purpose of this register is to point to the current instruction in memory that is being executed by the processor.

What is the role of program counter?

The program counter (PC) is a register that manages the memory address of the instruction to be executed next. The address specified by the PC will be + n (+1 for a 1-word instruction and +2 for a 2-word instruction) each time one instruction is executed.

What is example of program counter?

A program counter is a register in the CPU containing the address of the next instruction to be executed from memory. For example, when your computer is turned on, a signal places the decimal number F000 into the CPU. This action tells the computer to look at the first instruction on the motherboards flash memory chip.

How do you calculate program counters?

A program counter is one of the register used in computer architecture and os. It holds the address of next instruction to be executed. After instruction is executed, it will incremented by one,(PC =PC +1) moreover program counter will be point to the next instruction.


1 Answers

As you said, the "program counter" (also called "instruction pointer") is part of the hardware; more specifically, it's a processor register. The whole purpose of this register is to point to the current instruction in memory that is being executed by the processor. Once that instruction is executed, the PC is altered to point to the next instruction to be executed.

Most modern operating systems today are multitasking. This essentially means that they can run multiple processes at the same time. However, if you have just one processor, there's no way you can execute more than a process simultaneously, right? To create this illusion that more than one process is executing at the same time on only one processor, multitasking operating systems switch between runnable processes very fast: They advance one process, they pause it, and then they advance some other process, and so on, all this in fractions of a second.

To implement this mechanism, the operating system must have appropriate structures to keep the current status of all running processes. One of the most important values the operating system should keep in those structures is the current PC value for the process, which indicates where, in its program's code, it is currently executing.

like image 115
Pablo Antonio Avatar answered Sep 21 '22 23:09

Pablo Antonio