let’s say I have 2 processes and I have a variable I want to pass from the first one to the second one. I know I can declare a global variable and pass it by reference among differents functions, but I don’t know if it is possible to pass a variable among different processes.
I heard that each process is assigned its own portion of virtual memory and that one process cannot access another process’ memory space. Is it that true? Or is is actually possible for two processes to share a variable and therefore mutex mechanisms are needed?
No, it is not possible, at least not in the classical sense of passing a variable. You have many options, though: inter-process communication can be done through shared memory (sometimes implemented through memory-mapped files), named pipes, etc.