s are data structures used to store and retrieve data which can not be stored in CPU/processor registers. Stacks are usually accessed in a first-in-last-out fashion (Think stack of very heavy plates).
CPUs offer direct support for accessing stacks with stackpointer (and frame/base pointer) registers which are implicitly used by assembler instructions such as PUSH, POP, CALL, RET
. A CALL x
instruction pushes the current instruction pointer value onto the (current) stack and jumps to the instruction x (by loading it into the instruction pointer). A RET
instruction pops a value from the top of the stack and loads it into the instruction pointer. CALL and RET together are used to allow for nested subroutine calls
A software system can maintain multiple stacks, switching among them by reading and setting the stack pointer(s).
The memory space a (call) stack can occupy is limited and has to be managed. An operating system (OS) might allow application programs to maintain their own stacks, called user stack
s. This has the advantage that the OS does not need to care about the application programs needs regarding stack memory usage, stack orgranisation (where to place subroutine call argument values, subroutine local variable data etc.). Each simultaniously running application program needs its own stack, because the data stored on the user stack is how each program maintains its internal state.
But the OS also needs stack space (to be able to call OS-internal subroutines). The application program user stacks can not really be used for this, because the OS has to survive application program errors (like destroyed data structures on the stack). Therefore an operating system will maintain its own stack(s). These are called system stack
s. Application programs can not directly access system stacks.
is a data structure used by (Unix-like) operating systems to maintain information of files on secondary storage (Hard disks, Optical media etc.) A file directoy/file folder as stored on secondary storage is mostly a sequence of inodes (directory entries). If an application program accesses a file, it needs to maintain some internal data for that (like the abstract handle needed to identify the file to the operating system, the current read/write position relative to the beginnng of the file etc.). This is called a file descriptor
because it only references the real data structures used in the OS to coordinate access to the file by multiple concurrent application programs (Who is allowed to write? Can writing begin, or is some program still reading the same file data?).
I wrote this because I hope a generalized explanation of these concepts, focussed on their benefits (instead of technical details) might help Your understanding.