Wednesday, 15 June 2011

linux - where thread is implemented in memory? -


We know that the thread has its stack implemented within this process but my question This is that when thread is implemented in its stack, at that time it is a single stack used by process or any other work?

One more doubt is that

the short description will be appreciated

When the thread is implemented in its stack, it would be the same stack at the time Which is used by the process or any other?

There may not be enough parse on this but I think the summaries I get.

In most cases, in a multilevel application under Linux, all threads share the same address space each thread if it is running on a different processor then there may be local cache memory, but the entire address Location is shared by all threads. Even per thread stack space is shared by all threads - just each thread gets a different corresponding memory area.

But how does it share all these parameters within a single address?

This is also true about global variables, file descriptors etc. They all are shared.

Most thread implementations that run under Linux are using the clone (2) syscall to create new threads. To quote from:

The clone () creates a new process, which is similar to fork (2) in two ways. This is actually the top-level library function of the built-in clone () system call, which is later called sys_clone. Details of Sys_clone are given at the end of this page.

Unlike fork (2), these calls allow the child's process to share the parts of the context of their execution with the calling process, such as a memory location, table of file descriptor and a table of signal handlers.

You can see the process of cloning using linux under ps-eLf .

No comments:

Post a Comment