Stacks in linux - Linux

This is a discussion on Stacks in linux - Linux ; Hi, I'm little confused about stack in Linux. In Linux, while creating a process it's allocating a memory of 4kb/8kb which will be divided for stack and thread_info. So where is the text section, data section and heap is stored ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: Stacks in linux

  1. Stacks in linux

    Hi,

    I'm little confused about stack in Linux.

    In Linux, while creating a process it's allocating a memory of 4kb/8kb
    which
    will be divided for stack and thread_info.

    So where is the text section, data section and heap is stored for a
    normal C program ?

    Please clear my doubt.

    Thanks,
    Deepak

  2. Re: Stacks in linux

    On Nov 10, 2:37*am, deepak wrote:
    > Hi,
    >
    > I'm little confused about stack in Linux.
    >
    > In Linux, while creating a process it's allocating a memory of 4kb/8kb
    > which
    > will be divided for stack and thread_info.
    >
    > So where is the text section, data section and heap is stored for a
    > normal C program ?
    >
    > Please clear my doubt.
    >
    > Thanks,
    > Deepak


    They fault in as needed. When the process starts up and launches into
    its entry point, it will cause a page fault (because that page hasn't
    been mapped yet). The kernel will then allocate a page of memory, read
    the file from disk, map it into the process' address space, and return
    to the process. This will repeat for every page the process reads or
    writes.

    DS

  3. Re: Stacks in linux

    deepak wrote:
    > Hi,
    >
    > I'm little confused about stack in Linux.
    >
    > In Linux, while creating a process it's allocating a memory of 4kb/8kb
    > which
    > will be divided for stack and thread_info.


    This is the kernel stack.

    > So where is the text section, data section and heap is stored for a
    > normal C program ?


    These are user pages. See David's explanation.
    They are stored wherever the kernel finds space for it.

    Josef
    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html

  4. Re: Stacks in linux

    On Nov 10, 7:34*pm, Josef Moellers siemens.com> wrote:
    > deepak wrote:
    > > Hi,

    >
    > > I'm little confused about stack in Linux.

    >
    > > In Linux, while creating a process it's allocating a memory of 4kb/8kb
    > > which
    > > will be divided for stack and thread_info.

    >
    > This is the kernel stack.
    >
    > > So where is the text section, data section and heap is stored for a
    > > normal C program ?

    >
    > These are user pages. See David's explanation.
    > They are stored wherever the kernel finds space for it.
    >
    > Josef
    > --
    > These are my personal views and not those of Fujitsu Siemens Computers!
    > Josef Möllers (Pinguinpfleger bei FSC)
    > * * * * If failure had no penalty success would not be a prize (T.. *Pratchett)
    > Company Details:http://www.fujitsu-siemens.com/imprint.html


    So what are the contents in kernel page stack. Is this kernel stack
    points to the user pages?

    Thanks,
    Deepak

  5. Re: Stacks in linux

    On Nov 10, 7:38*am, deepak wrote:

    > So what are the contents in kernel page stack. Is this kernel stack
    > points to the user pages?
    >
    > Thanks,
    > Deepak


    The kernel page stack is only used when the process runs in the
    kernel. It contains kernel stack frames only.

    User stack pages, as well as other user pages, are mapped as needed.

    DS

  6. Re: Stacks in linux

    On Nov 10, 8:49*pm, David Schwartz wrote:
    > On Nov 10, 7:38*am, deepak wrote:
    >
    > > So what are the contents in kernel page stack. Is this kernel stack
    > > points to the user pages?

    >
    > > Thanks,
    > > Deepak

    >
    > The kernel page stack is only used when the process runs in the
    > kernel. It contains kernel stack frames only.
    >
    > User stack pages, as well as other user pages, are mapped as needed.
    >
    > DS


    Oh.. Now I got it. So this stack will be used when user changes from
    user mode to kernel mode.

  7. Re: Stacks in linux

    On Nov 10, 8:22*am, deepak wrote:

    > Oh.. Now I got it. So this stack will be used when user changes from
    > user mode to kernel mode.


    When the process does. Every process that is not currently running on
    a CPU is in its kernel stack.

    DS

  8. Re: Stacks in linux

    deepak writes:

    > Hi,
    >
    > I'm little confused about stack in Linux.
    >
    > In Linux, while creating a process it's allocating a memory of 4kb/8kb
    > which
    > will be divided for stack and thread_info.
    >
    > So where is the text section, data section and heap is stored for a
    > normal C program ?
    >
    > Please clear my doubt.


    read /proc/*/maps

  9. Re: Stacks in linux

    David Schwartz wrote:
    > On Nov 10, 8:22 am, deepak wrote:
    >
    >> Oh.. Now I got it. So this stack will be used when user changes from
    >> user mode to kernel mode.

    >
    > When the process does. Every process that is not currently running on
    > a CPU is in its kernel stack.


    As is every process that executes kernel code, e.g. a system call or an
    interrupt handler, though the latter may very well use a separate stack
    alltogether.

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html

+ Reply to Thread