Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 24th, 2007, 10:21 PM   #1
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
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)
programmingnoob is offline   Reply With Quote
Old Mar 24th, 2007, 10:53 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
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.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC