Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a variable of the another program in C

Tags:

c++

python

c

In python, you can learn memory location of variables by using id function, so:

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

I'm tried to access to variable with pointers in C (Surely the other program still alive):

#include <stdio.h>

int main(void){
    char *x = (char *) 0x7F27483876F0;
    printf("%s\n", x);

    return 0;   
}

I compile the code, no errors or warnings but when i tried the running program OS giving a Segmentation error. How i can solve this problem?

Or is it possible?

like image 389
A. Ite Avatar asked Jun 08 '16 09:06

A. Ite


1 Answers

Doing something like this is more and more impossible these days. With features like address space layout randomization you can't really tell where a given program, let alone variable will load in actual memory.

Best bet is to use some type of message passing. Not sure why all the downvotes on your question, but it seems like a reasonably put question, even if not technically feasible these days.

like image 172
jsquaredz Avatar answered Sep 28 '22 13:09

jsquaredz