Multithreaded program in C: calculating thread stack space
Situation:
I am writing a program in C 开发者_如何学JAVAthat maintains a number of threads. Once a thread ends, a new one is created.
Each thread forks - the child runs a PHP process via exec() and the parent waits for it to finish.
Each PHP process takes the next item from a queue, processes it and exits.
Basic code: http://www.4pmp.com/2010/03/multitasking-php-in-parallel/
Problem:
The PHP processes are Symfony tasks and Symfony requires a fairly huge amount of memory. How can I safely calculate the required stack space for each thread so that PHP processes will have enough memory?
The memory limit set in php.ini is 128Mb so should I allocate this much space in the stack?
When you fork
you get a new process, when you exec
the process is replaced by the one you execute. So any setting of stack space in the C program are irrelevant with regards to PHP memory usage.
In one way YES.. because, since the PHP.ini is restricting the memory usage/limit to 128 MB, we know that it is the max memory the PHP process is going to use. So, its better to allocate such space for each thread [ safe side.. double the size of it ].
精彩评论