Posted on August 16, 2016 at 11:51To answer this questions it is necessary to give a clear definition about the words ''ram'' and ''used''.
Ram usually consist of heap and stack memory. If you are using some operating system it should be possible to calculate how much stack that was allocated for each process, however that will lead us to the question above of what ''used'' really means. When it comes to heap it will get a little more difficult. If you have control over the malloc and free functions is could be possible to keep some counter here tracking the allocated memory (given that malloc is always used to allocate memory). To count the stack usage you could also just subtract the stack pointer from the start of the stack (probably found in link script).