how can i determine that
what percentage of stack region is currently is used?
(i am using tru64 unix)
Most solutions are going to be very specific to the exact OS involved. Poking around on FC5, I see that Linux has this kind of info available in the /proc filesystem. Excerpt from "man 5 proc":
/proc/[number]/stat
Status information about the process. This is used by ps(1). It is defined in
/usr/src/linux/fs/proc/array.c.
The fields, in order, with their proper scanf(3) format specifiers, are:
startstack %lu
The address of the start of the stack.
kstkesp %lu
The current value of esp (stack pointer), as found in the kernel stack page for the process.
So maybe you can look at Tru64 to see if it has anything like that.
Here is a crazy idea that might work on any OS to get a good approximate value. Earlly in main() take the address of an auto variable and store the address for future reference. Later, when you want to check the stack size, allocate a new auto variable and now subtract the addresses and take the absolute value to get an approximate stack size.
struct rlimit rlim;
getrlimit(RLIMIT_STACK, &rlim);
printf("STACK: cur - %ld max - %ld\n", rlim.rlim_cur, rlim.rlim_max);
rlim.rlim_cur shows current usage for the process. I think the OP wants all stack usage (across all processes), which I have no idea how to get. That would be totally internal to the kernel for each OS.