I need to get start and end address of following process segments : code, data,stack, environment. I understand how is it located in memory, but don't know how to get it using api calls or something else. I have found how to get start of some segments using this code
#include <stdio.h>
int temp_data = 100;
static int temp_bss;
void print_addr ( void )
{
int local_var = 100;
int *code_segment_address = ( int* ) &print_addr;
int *data_segment_address = &temp_data;
int *bss_address = &temp_bss;
int *stack_segment_address = &local_var;
printf ( "\nAddress of various segments:" );
printf ( "\n\tCode Segment : %p" , code_segment_address );
printf ( "\n\tData Segment : %p" , data_segment_address );
printf ( "\n\tBSS : %p" , bss_address );
printf ( "\n\tStack Segment : %p\n" , stack_segment_address );
}
int main ( )
{
print_addr ();
return 0;
}
But I don't know how to find end of each segment. I have only idea is that the end of one segment is the start of another segment. Please explain how can I do this using C and linux API.