Accessing a variable of another program in C

In python, you can find out the memory location of variables using the id function, therefore:

X = "Hello world!" print(id(X)) # Output is equal to 139806692112112 (0x7F27483876F0) 

I am trying to access a variable with pointers in C (of course, another program is still alive):

 #include <stdio.h> int main(void){ char *x = (char *) 0x7F27483876F0; printf("%s\n", x); return 0; } 

I am compiling the code, no errors or warnings, but when I tried to start the OS, giving a segmentation error. How can I solve this problem?

Or is it possible?

+5
source share
1 answer

To do something like this these days is more and more impossible. With features such as randomizing address space allocation, you cannot tell where a given program, let alone a variable, will load in real memory.

It is best to use some type of messaging. Not sure why all the problems are on your question, but this seems like a reasonable question, even if it is technically impossible these days.

+4
source

All Articles