I'm solving a problem in which I'm given several processes, each with it's own required CPU time for completion, memory requirements and time of entry to the ready queue. The algorithm the scheduler uses to assign them is Shortest Remaining Time(SRT). The system has a limited amount of memory of which a portion of is taken up by the OS.

My question is, if a certain process(P1) takes 8 time units to complete and is already in memory and another one(P2) enters the ready queue with 3 time units until completion but the most of the memory is taken up by P1, does P1 get kicked out of memory or does it stay on the CPU up until completion?

  • You say a process "gets kicked out of memory"; could you clarify where it would get kicked to, exactly? Your last question doesn't entirely make sense – on usual PC architectures, the CPU and the main memory (RAM) are orthogonal. (Are you talking about e.g. the CPU's built-in cache instead?) – grawity Jul 11 at 14:13
  • 1
    And if the question isn't about usual PC architecture, then it's a bit offtopic for the site and probably needs 1) more detail and 2) cs.stackexchange.com or such – grawity Jul 11 at 14:15
  • 1
    "it depends" - what operating system are you considering, and do you differentiate between physical memory and swap / pagefile? – Attie Jul 11 at 14:39
  • @grawity yeah cs.stackexchange.com sounds like a better place to ask the question since the problem I'm solving is more regarding the general understanding of the way processes get assigned in any OS. thanks for the input! – bambooch Jul 11 at 17:20

Processes as implemented by most modern OSes like Linux, Windows, etc. stay in memory until they exit or are terminated by the operating system itself.

Processes typically exit when they are completed, but some may be designed to never exit unless sent a signal by the operating system; daemons and services fall in this category.

If the operating system doesn't have enough memory to load a process, the behavior is OS dependent. The OS can report that it could not start the process due to not having enough memory, or the OS can be designed another way - maybe it would forcibly terminate the process running the most time. Or the OS/scheduler could just crash or restart.

Waiting until there is enough memory to actually load the process is an interesting strategy, but this often isn't workable because most processes don't consume a fixed amount of memory after they start - they often request more memory for dynamic variables/structures from the OS depending on what they are configured to do or are trying to do, and this is not easily predictable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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