Quote:
Originally Posted by rpittala
we can use a simple global variable for the above operations and that solves the problem.
|
Processes run in their own, separate memory space. There is no such thing as a "global variable" shared between two processes.
You may have two processes, each running the same executable, which means each references all its variables with the same names, but each variable is unique to each process.
There is no sharing.
Think of it a different way. Let's pretend what you describe is how things work. Let's take the example above (e.g. two processes running the same executable). Suppose I run process A to do task #1 and process B to do task #2. Task #1 and task #2 might require different values for the global variables to perform their respective tasks. So what happens? Task #1 and task #2 "fight" each other or get "confused" because the
other process changed the value of a global variable.
If you want two processes to communicate, you must use IPC of some form.
Contrast this with threads. Threads run inside the same memory space as the process that started the thread(s). Global variables can be used for
some communication between threads--because the variable name resolves to the same location in the same memory space.