I just started deal with pointers in C, and one stuff confusing me...
Here is simple code:
Code:
int main ()
{
int var1 = 10;
int var2 = 20;
long ms = 10000000;
printf("Address of var1 variable: %p\n", &var1 );
printf("Address of var2 variable: %p\n", &var2 );
retpid();
millisleep(ms);
return 0;
}
And - it's return var1 and var2 memory address (virtual memory, I believe?):
Code:
$ ./address
Address of var1 variable: 0x7fff0d7f7984
Address of var2 variable: 0x7fff0d7f7980
PID = 16496
But - when I run pmap - I don't see this addresses there:
Code:
# pmap -x 16496
16496: ./address
Address Kbytes RSS Dirty Mode Mapping
0000000000400000 4 4 0 r-x-- address
0000000000600000 4 4 4 rw--- address
00007f79cf8b8000 1576 260 0 r-x-- libc-2.12.so
00007f79cfa42000 2048 0 0 ----- libc-2.12.so
00007f79cfc42000 16 16 16 r---- libc-2.12.so
00007f79cfc46000 4 4 4 rw--- libc-2.12.so
00007f79cfc47000 20 12 12 rw--- [ anon ]
00007f79cfc4c000 128 104 0 r-x-- ld-2.12.so
00007f79cfe5c000 12 12 12 rw--- [ anon ]
00007f79cfe69000 8 8 8 rw--- [ anon ]
00007f79cfe6b000 4 4 4 r---- ld-2.12.so
00007f79cfe6c000 4 4 4 rw--- ld-2.12.so
00007f79cfe6d000 4 4 4 rw--- [ anon ]
00007fff0d7e5000 84 12 12 rw--- [ stack ]
00007fff0d7ff000 4 4 0 r-x-- [ anon ]
ffffffffff600000 4 0 0 r-x-- [ anon ]
---------------- ------ ------ ------
total kB 3924 452 80
I guess - it's is inside stack:
Code:
# cat /proc/16496/maps | grep stack
7fff0d7e5000-7fff0d7fa000 rw-p 00000000 00:00 0 [stack]
But - how I can obtain this variables addreses, to see them with `pmap`? If I put them as "global":
Code:
...
#include <stdlib.h>
#include <sys/types.h>
int var1 = 10;
int var2 = 20;
int millisleep(unsigned ms);
int retpid(void);
int main ()
{
// int var1 = 10;
// int var2 = 20;
long ms = 10000000;
printf("Address of var1 variable: %p\n", &var1 );
printf("Address of var2 variable: %p\n", &var2 );
retpid();
millisleep(ms);
return 0;
}
...
I have odd addresses in result:
Code:
Address of var1 variable: 0x600a94
Address of var2 variable: 0x600a98
Thanks.