0

Someone told me that Linux can run on CPUs which do not support multiple tasks.

But if you have one core only which doesn't support multitasking, how does Linux implement multitasking?

Let's say I want to run two programs which need 1h to terminate each. How does Linux pause the first program after ~100ms to switch to the second program?

Here are 2 scenarios I can think of:

  • It's not possible to run multiple tasks at once.
  • Linux uses a hardware timer to interrupt running processes.
2

1 Answer 1

5

It’s not clear to me what you mean by a CPU that supports multiple tasks. I guess you’re thinking of multi-core CPUs, but they aren’t a pre-requisite for multitasking; multitasking operating systems pre-date multiple-CPU systems (let alone multi-core CPUs).

However as far as pausing a process to run another is concerned, Linux uses a variety of techniques, including hardware timers (indirectly). Essentially, any time the kernel is invoked, it can decide to change the running process. See the following posts for details:

13
  • What is unclear about CPUs not supporting multitasking? I mean what it is. I know that there are single core CPUs supporting multitasking. Commented Mar 4, 2024 at 14:45
  • 2
    @zomega a "task" is an OS concept. a CPU doesn't know what a "task" is. CPU just runs machine code. The only thing that's required from the CPU is a timer interrupts. Without this it cannot run Unix/Linux. When the CPU receives the interrupt, it returns to a specific code at the kernel that would then switch the CPU from one task to another. If the CPU can run an operating system, then by extension it support multitasking. Commented Mar 4, 2024 at 15:12
  • 2
    @zomega that was added to help support tasks on x86 CPUs, but the concept is still an OS concept rather than a CPU concept, and an OS can define tasks without relying on that kind of CPU feature (in fact, task support on x86 turned out to not be a great idea). All multi-tasking (and many single-tasking) operating systems define tasks, but many of them run on CPUs which don’t define tasks at all. Commented Mar 4, 2024 at 16:20
  • 1
    @zomega “is it necessary to name an example CPU to answer the question?” — you seem to have one in mind, I’m curious to know what it is. Commented Mar 4, 2024 at 16:20
  • 1
    @zomega, pretty much all you need to switch tasks is the ability to cleanly save and replace the CPU registers (including the stack pointer and instruction pointer). Most CPUs have push/pop and call/return/jump instructions, so it's not actually that easy to name one that doesn't support multitasking. It's not too hard to implement switching on an ATmega either. Memory protection of course is an entirely different issue. Commented Mar 4, 2024 at 17:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.