Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 06-27-2012, 07:43 AM   #1
LQ Newbie
Registered: Jun 2012
Location: India
Posts: 10

Rep: Reputation: Disabled
Linux Kernel Programming

Can you please explain me, What is system Stack and what is user stack.
Also, please tell me difference between File Descriptor and inode ?

I tried to read from Charles Crowley but still confused.

Please explain
Old 06-28-2012, 02:27 AM   #2
LQ Newbie
Registered: May 2007
Location: Berlin, FRG
Distribution: Ubuntu
Posts: 22

Rep: Reputation: 4
Stacks 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 stacks. 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 stacks. Application programs can not directly access system stacks.
An inode 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.

Last edited by Jebram; 06-28-2012 at 02:41 AM. Reason: Inserted Wikipedia links.
Old 07-21-2012, 08:14 AM   #3
Registered: May 2012
Location: Beijing China
Distribution: Asianux
Posts: 56

Rep: Reputation: Disabled

For Stack:

1) Each task (thread), has its own user stack, and kernel stack, also may have interrupt stack under some platform and with relative configuration.

2) user stack is used when the task is running in user mode, kernel stack is used when the task is running in kernel mode. the interrupt stack (if have) is used when the task is interrupted by System Interrupt or Exception.

3) kernel stack and interrupt stack are all belong to system stack.

For inode and fd:

1) inode is the one of element for file system data orgnization, it is can existance on disk (independant OS).

2) fd is the one of resoure descriptor for running environment, it is depend on OS, and only existance in task running environment (multi tasks can share one fd, but fd still depend on the task environment).

3) one inode can be relative with multiple fds, these fds can be in differenct tasks, even on different machines(for example: NFS file system)

Hope these information above are helpful for you.

: )

Last edited by gchen; 07-21-2012 at 08:20 AM.
2 members found this post helpful.
Old 07-21-2012, 12:18 PM   #4
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,514
Blog Entries: 4

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
Also bear in mind that system stack contents are trusted; the contents of user space are not. When a process executes a system call, the return-context information must be stored in a trusted place. As the operating system performs its own subroutine calls, that must also be done in a trusted place.

It's easy to see why this is necessary. Let's say that a runaway (stupid, but innocent) process completely blows its stack... there only 2 miserable bytes left... and it executes a system call. There is no room on the user stack to store any context information. Therefore, the kernel takes a very simple strategy: it ignores completely what "the poor, miserable user" is doing, and maintains for itself a stack upon which it can safely rely.

Last edited by sundialsvcs; 07-24-2012 at 04:35 PM.
2 members found this post helpful.
Old 12-11-2012, 05:29 AM   #5
LQ Newbie
Registered: Jun 2012
Location: India
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks Everyone ....................


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Kernel Programming ganeshbonal Programming 10 09-15-2008 04:49 AM
Linux kernel debugging and Linux kernel module programming Igor007 Programming 2 08-13-2005 05:12 AM
Linux kernel debugging and Linux kernel module programming Igor007 Linux - Enterprise 3 08-12-2005 02:47 PM
linux kernel programming poojavarshneya Red Hat 2 09-19-2004 10:54 PM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration