LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 11-15-2015, 09:50 PM   #1
particlereddy
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Rep: Reputation: Disabled
stack limit of Process and stack limit of thread


Hi All,
Please answer this question.

1. Assuming a linux-86/32 bit systems, the stack size of a process is 8 Mega Bytes .

if a pthread is being formed within that process, the pthread_attr_getstacksize function throws the stack size as 8MB? how come it is possible, that means all the PROCESS STACK == PTHREAD STACK?

what happens if a second thread is spawn?

Thanks
vlsireddy
 
Old 11-15-2015, 10:18 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I believe you have an answer, or the start of an answer, at the pthread_create man page.
 
1 members found this post helpful.
Old 11-16-2015, 07:51 PM   #3
particlereddy
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi Sir,
Thanks for your answer. Excellent source. [on an other note, i searched it a lot, could not find the exact answer, but your link helped me understand it].

1. to wrap it up, in this case of 3 threads [the ulimit -s is set to 8MB]


./a.out hola salut servus

each of 3 threads [hola, salut, servus] come up with 8 MB of stack and as a whole can i conclude that PROCESS has 8*3=24MB of
stack with it.

In other words, Linux has dynamically extended the stack of process by 3 times [24MB]

Thanks
 
Old 11-16-2015, 07:58 PM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by particlereddy View Post
Hi Sir,
Thanks for your answer. Excellent source. [on an other note, i searched it a lot, could not find the exact answer, but your link helped me understand it].

1. to wrap it up, in this case of 3 threads [the ulimit -s is set to 8MB]


./a.out hola salut servus

each of 3 threads [hola, salut, servus] come up with 8 MB of stack and as a whole can i conclude that PROCESS has 8*3=24MB of
stack with it.

In other words, Linux has dynamically extended the stack of process by 3 times [24MB]

Thanks
That's how I understand it as well.
 
Old 11-16-2015, 10:42 PM   #5
particlereddy
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi,
i ran a quick simulation of finding the local variable address in PROCESS at main() and then find the address of local variable inside FIRST created pthread, seriously i dont see any relationship


[root@localhost threads]# ./threadex 1
threadinfo structure size 24
Thread 1: top of stack near 0x7f436d9deee8; argv_string=1
Joined with thread 1; returned value was 1
address of a 0x7fff66a5ffd8

main() function first local variable address: 0x7fff66a5ffd8
FIRST PTHREAD address: 0x7f436d9deee8

there is huge difference between above 2 hex numbers. looks like process has the luxury of all the system memory available as its stack

please let me know if you can reason why is it so?

this is x86-64 bit system.

Thanks
 
Old 11-16-2015, 11:55 PM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by particlereddy View Post
there is huge difference between above 2 hex numbers. looks like process has the luxury of all the system memory available as its stack

please let me know if you can reason why is it so?
It's virtual memory, in other words the process thinks it has a full 64-bit address space for itself, actually orders of magnitude more than system memory. In reality, only those pages that are in used are mapped to physical memory by the MMU (at least that was state of the art 25 years ago), the others only exist in the process' fantasy.

You are not the first one with questions about process memory layout. An internet search of "linux process memory layout" results in some ten million hits. This is a good example: http://stackoverflow.com/questions/1...eaded-process; I'll leave it up to you to read the 9999999 others
 
Old 11-17-2015, 07:26 AM   #7
particlereddy
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi Sir,
Thanks. No more questions to you. I will reply back with all answers and understanding.

Thanks
 
Old 11-21-2015, 01:51 PM   #8
particlereddy
LQ Newbie
 
Registered: Nov 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi,
i got the answer. I was always thinking from the diagram perspective of stack, heap, bss, data,text. But this post tells that it is obsolete and now all the experiments which i did fall in place w.r.t to thsi post.

http://stackoverflow.com/questions/2...or-each-thread
 
  


Reply



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
What is the lower limit on the stack size ? jana_van Linux - Newbie 5 08-04-2014 06:49 AM
Why the stack size limit? hydraMax Programming 4 05-02-2011 08:07 PM
single 8K process stack vs 4K process stack and a seperate 4K interrupt stack charvak Linux - Kernel 1 03-17-2010 06:58 PM
How to set Stack/Heap Limit ? gloridel Linux - Kernel 1 06-11-2007 02:56 AM
Max Stack Size limit on Linux 2.4 rhegde Debian 0 08-08-2006 02:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:33 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
Open Source Consulting | Domain Registration