7
$\begingroup$

I'm reading about an operating system but some concept confuses me.

What doesn't confuse me:

When an interrupt or system call or processor exception occurs, it happens when user mode tries to switch to the kernel mode, the operating system uses PCB(process control block) to save needed stuff, namely - hardware completing previous instructions, saves program counter, stack pointer, registers, changes execution state and so on. For each process has a separate process control block. This seems logical.

What confuses me:

But after several subchapters, I've read that interrupt or system call or processor exception occurs, an operating system needs to save some information - program counter, stack pointer, registers, execution state and so on. But this time saves not in PCB, it saves in "interrupt stack". It also said for each process needs the separate location of "kernel stack".

After that appears a few questions:

  • Is "interrupt stack" and "kernel stack" the same thing, just different named?

  • If the operating system already has PCB, why it needs to use "kernel stack. Yes, for each process operating system has separate PCB. And
    the separate location for each process in kernel stack.

  • Does the operating system use both kernel stack and PCB? If it does, why not just one of these?

  • What difference between PCB and kernel stack, if they are used for the same tasks

P.S Operating System Principles and Practice

$\endgroup$

2 Answers 2

1
$\begingroup$

The operating system cannot continue using user-accessible memory when it is handling an interrupt, that program may be buggy, malicious, or worse. It may overwrite any part of its address space at any time. That includes the stack.

The stack is often a critical part of the execution of a program, so the operating system has no choice other than to switch to another stack, which the user mode program can't corrupt.

The PCB holds information about a task. When that task is not running, the PCB may hold the context.

There may be two different kinds of context saves, one for switching from one task to another, and one just for when it is preempted by an interrupt. The latter is held on the interrupt stack, which as mentioned is separate from the user mode stack for security and correctness reasons.

Unless there is some microarchitectural reason to have a special stack for interrupts, kernel stacks and interrupt stacks are very similar, only differing in when they are used. The specifics about the stack are implementation details.

$\endgroup$
1
$\begingroup$

The interrupt has nothing to do with a process. On a multi- processor system, a process can be killed five nanoseconds after starting to process an interrupt, and the PCB is gone. And with it, all the information about the interrupt that you stored.

You don’t want to mix up interrupts and switching between processes. They are independent.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.