LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 06-27-2012, 08:43 AM   #1
ram619
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
Thanks
 
Old 06-28-2012, 03:27 AM   #2
Jebram
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 03:41 AM. Reason: Inserted Wikipedia links.
 
Old 07-21-2012, 09:14 AM   #3
gchen
Member
 
Registered: May 2012
Location: Beijing China
Distribution: Asianux
Posts: 56

Rep: Reputation: Disabled
Smile

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 09:20 AM.
 
2 members found this post helpful.
Old 07-21-2012, 01:18 PM   #4
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
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 05:35 PM.
 
2 members found this post helpful.
Old 12-11-2012, 06:29 AM   #5
ram619
LQ Newbie
 
Registered: Jun 2012
Location: India
Posts: 10

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


Reply


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 05:49 AM
Linux kernel debugging and Linux kernel module programming Igor007 Programming 2 08-13-2005 06:12 AM
Linux kernel debugging and Linux kernel module programming Igor007 Linux - Enterprise 3 08-12-2005 03:47 PM
linux kernel programming poojavarshneya Red Hat 2 09-19-2004 11:54 PM


All times are GMT -5. The time now is 10:10 PM.

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