How to find out the stack size occupied for a process?

Hi,

In Linux how to find out what will be the stack size allocated for a process?

Actually i have to fork n number of processess, and will call exec. I will be execing an executable which is already multithreaded and each thread size is defined. My doubt is how to know if the size of the stack created by the process will be sufficient for the already existing multitthreaded process. Can anyone help me in this please??

Thanks

hello !
maybe if u check out the man of brk command will help. :slight_smile:

Call sysconf() with PTHREAD_STACK_MIN - this gives you the minimum required stack for each thread. Multiply by the number of concurrent threads you know will exist.

Next, call getrlimit() with AS_STACK to see if there is a stack size limit for any new process your parent will create. If there is one and it is too small, then you have to call setrlimit (if you have privs) to raise the hard limit to get a stack size you can live with.

Most Linux systems have no stack limits set, but it sounds as if your does.

With regard to brk, ulimit() will return the current max brk size allowed -- with UL_GETMAXBRK. I don't know how that relates to your problem exactly.