简体   繁体   中英

Process Instructions storage (Operating System)

I was learning about how a process looks inside a memory from(OS concepts by Abraham silberschatz). So I came to know that it mainly has following section

  1. HEAP
  2. STACK
  3. DATA/ R/WCode( for global variables)
  4. Text(or ROC) that contains the code
  5. Shared library
  6. OS reserved space
  7. List item

Diagram link

I have some questions regarding the process workflow.

  1. Where does PCB fits in this diagram.

  2. People generally show the called functions getting pushed onto the process stack in memory, but in actual 3 pieces of info gets pushed(local variable, parameters passed and return address).Two sub-questions here:

    2.1 Where are the actual instructions stored in this diagram(because stack only has data not instructions). Is it in the text section.

    2.2 if this stack data is pushed then they must get popped when the function execution is completed.So how does Return-Address comes into play while popping.

That "Figure 3.1 - A process in memory", shows the address space of a process. Each process typically has its own address space (not depicted), and the kernel also typically has its own address space (also not depicted).

The PCBs usually live within the kernel, who is managing the processes.

Functions, when then are not active, still have machine code instructions which are located within the text segment/section of the process.

Functions that are invoked are said to be activated, and an activation record, also known as a stack frame or call frame, is created on the stack for some functions, depending on how complex the function is. (The stack frame or activation record is effectively private data to the function, not generally intended for other functions to inspect, modulo exception (throw/catch) mechanisms)

A function, X, that calls another function, Y, will suspend itself upon the invocation of Y waiting for Y to return to X, before X resumes. In such scenario, X uses an activation record on the stack to maintain its suspended state, which it will use upon resumption.

If/when function Y returns to X it must remove any data that it (Y) allocated on the stack, and restore the stack pointer, and other call-preserved registers, to their original value(s) in order for X to successfully resume. The stack pointer register is the reference for a function to find its stack allocated data.

When X calls Y we can speak to the presence of two return addresses: X has a return address to get back to its caller, and Y has a return address to get back to X. As this is the nature of calling, some architectures will provide instructions for calling that also push the return address directly onto the stack, and provide instructions for returning that pop the return address off the stack to resume the caller.

However, RISC architectures will generally leave the return address in a CPU register, requiring functions that make further calls to save their own return address in a place that will survive their own further calling (that place being stack memory). RISC architectures also tend to engage in less pushing and popping, collecting all stack frame allocations into one (larger) allocation in prologue and all stack frame deallocations into one (larger) deallocation in epilogue.

The suspension, invocation, returning, and resumption is logical, from the point of view of functions: though the processor doesn't really see or care about functions, but rather instead sees a continuous stream of instructions that happen to include various forms of branching.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM