1

Let's assume we have 2 programs written in C, one program allocates memory with malloc and launches the second program passing the address of allocated memory and size as arguments.

Now the question, is it possible for the second program to cast the first argument to a pointer and read/write to that memory. Why, why not?

For the sake of simplicity assume Linux as the underlying OS.

1 Answers1

0

No, because on modern operating systems processes running in user mode see Virtual Memory. The same virtual address will translate to a different physical address or page file location between processes.

Fortunately, most operating systems do have APIs that allow for inter-process communication, so you can research those methods. This question seems to be a good place to start, since you claim to be working on Linux.

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85