![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 155
Rep Power: 3
![]() |
shared variable
how would you create a shared variable in C so that all processes can use it?
if you could post any links, then I would appreciate it. (I tried googling it, but it didnt help) |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
The literal answer is that you can't. C doesn't support the concept of processes, let alone anything related to sharing data between processes.
Having given the literal (and correct) answer, I'll give some practical pointers. The notion of a "process" is highly operating system specific. A process has different characteristics under windows than under unix. The means of sharing data between processes are similarly operating system dependent. A fair few modern operating systems provide some means of synchronising processes (eg mutexes) and it is possible, using techniques that are usually specific to both operating systems and hardware to set up shared areas of memory. The more usual means of sharing data between applications are highly variable; - Process A writes data to a file, and process B reads that file; - Use of sockets to pass data between cooperating processes (eg process A writes data to a socket, and process B receives data from the socket); - Other means of other inter-process communications (eg mailboxes) between cooperating processes; - Use of distributed object frameworks (eg CORBA which is able to be implemented using features of multiple operating systems, DCOM which is Microsoft OS specific, etc); - Use of services that are built on top of distributed object frameworks (eg CORBA services) - Use of database servers (eg process A sends data to another process which is a database server, and the database server provides a copy of the data to process B) But none of these means give a means of simply having a shared variable that can be shared between all processes. Most, if not all, require processes to communicate data between them in some way rather than just creating a "shared" area of memory so all processes can access. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is this declaring a variable? | waveform | C++ | 21 | Jun 23rd, 2006 4:48 PM |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 6:41 PM |
| Pointers in C (Part II) | Stack Overflow | C | 2 | Apr 29th, 2005 11:39 AM |
| Pointers in C (Part I) | Stack Overflow | C | 4 | Apr 28th, 2005 8:03 PM |
| variable problem | robert_sun | C | 1 | Apr 12th, 2005 3:10 PM |