C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2010, 02:25 PM
andy101 andy101 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: UK
Posts: 196 andy101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
Rebuild and install Shared Library

I have updated a program whih has a shared library so that other programs can access some of its data.
However these other programs are getting 0 for data items they try and access via the shared library, non zero values exist. I have deleted all the .obj files and re-compiled them, but still the same problem including the shared library code.

Are they any way to ensure that all copies/version of the old shared library are removed and that the new one is being used.

Shared memory is being used by many of these programs and I have seen a similar problems before, but re-building usually sorted it out. Note they are a few accounts in the sytems.

Any suggestions?

Andy

Reply With Quote
  #2  
Old October 19th, 2010, 06:18 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 989 L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 22 h 45 m 6 sec
Reputation Power: 362
Send a message via AIM to L7Sqr
This is highly dependent on so many things you fail to mention.
What platform?
Assuming no interface changed, are the calls executing successfully - did you make provisions for when they do not?
Code would also be helpful so that we be relatively sure you haven't introduced some typo that might waste everyone's time.
__________________
True happiness is not getting what you want, it's wanting what you've already got.

My Blog

Reply With Quote
  #3  
Old October 20th, 2010, 08:05 AM
andy101 andy101 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: UK
Posts: 196 andy101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
Quote:
Originally Posted by L7Sqr
This is highly dependent on so many things you fail to mention.
What platform?
Assuming no interface changed, are the calls executing successfully - did you make provisions for when they do not?
Code would also be helpful so that we be relatively sure you haven't introduced some typo that might waste everyone's time.

I think the problem is with Shared Memory. The main program creates shared memory and the shared library should use this shared memory. It does a open or create on this shared memory.
My test program that uses the shared memory library returns zeros. It looks like the shared library has created a new shared memory area.
Is it the order of building the units? As two shared memeory items seem to exist with the same ID or name.
Question how to clear out the shared memory and start all over again so that only one exists!

Code:
shm_id = shmget(key, shm_size, (IPC_CREAT | IPC_EXCL | shmflg));

Reply With Quote
  #4  
Old October 20th, 2010, 08:44 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 989 L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 22 h 45 m 6 sec
Reputation Power: 362
Send a message via AIM to L7Sqr
Zero is an appropriate return value from shmget. Is there a reason that you think that it is an error to get that?

In linux:
Code:
ipcs -m
will list the shared memory segments. You can use
Code:
ipcrm -m ...
to remove those entries.

Reply With Quote
  #5  
Old October 20th, 2010, 11:52 AM
andy101 andy101 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: UK
Posts: 196 andy101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
Sorry the return values I get is from call using the shared library. I know a little about shared memory keys and thier association with the file system. I will try the ipcrm -m option when I get on the system.

I just wondered if any command to remove the shared library or to see the shared memory its using.

Reply With Quote
  #6  
Old October 21st, 2010, 11:25 AM
andy101 andy101 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: UK
Posts: 196 andy101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 10 h 57 m 49 sec
Reputation Power: 9
My test program works some times. I am wondering if they are any settings to allow multiple access to the Shared Memory?

The code is as floows:-

Code:
     SHM_EMU = (void *)shmat(shm_id, (void *)0, 0);  

      if (SHM_EMU == (void *)-1) {
         printf("\nAttach Shared Memory Error\n");
         return (void *)-1;
      } else {
         printf("\nAttach Shared Memory %d \n", shm_id);
         return SHM_EMU;
      }


The shared library just calls this routine once only.

Reply With Quote
  #7  
Old October 22nd, 2010, 05:25 AM
mitakeet's Avatar
mitakeet mitakeet is offline
I'm Baaaaaaack!
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 5,538 mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 242
I don't know the specifics, but there are flags that allow for multiple access to shared memory (hence the moniker 'shared'). Google will be your friend here.
__________________

My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
Free code: http://sol-biotech.com/code/.
Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up

The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw

Reply With Quote
  #8  
Old October 22nd, 2010, 09:27 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 989 L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 22 h 45 m 6 sec
Reputation Power: 362
Send a message via AIM to L7Sqr
I'm still not sure of what it is you are doing outside of the context you provide, but here is a short example that works as I believe you want it to.
c Code:
Original - c Code
  1. /* produce.c */
  2. #include <string.h>
  3. #include <sys/shm.h>
  4. #include <sys/ipc.h>
  5.  
  6. int main () {
  7.  
  8.     int shmid = 0, value = 42;
  9.     key_t shmkey = 2;
  10.     char * mem = 0;
  11.  
  12.     shmid = shmget (shmkey, 1024, IPC_CREAT | IPC_EXCL | SHM_R | SHM_W );
  13.     mem = shmat (shmid, 0, 0);
  14.     memcpy (mem, &value, sizeof (value));
  15.     shmdt (mem);
  16.  
  17.     return 0;
  18. }
c Code:
Original - c Code
  1. /* consume.c */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <sys/shm.h>
  5. #include <sys/ipc.h>
  6.  
  7. int main () {
  8.  
  9.     int shmid = 0, value = 0;
  10.     key_t shmkey = 2;
  11.     char * mem = 0;
  12.  
  13.     shmid = shmget (shmkey, 1024, 0);
  14.     mem = shmat (shmid, 0, 0);
  15.     memcpy (&value, mem, sizeof (value));
  16.  
  17.     printf ("Read '%d' from shared memory location\n", value);
  18.  
  19.     shmdt (mem);
  20.     shmctl (shmid, IPC_RMID, 0);
  21.  
  22.     return 0;
  23. }
With those you can follow with:
Code:
$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status  
$ ./produce
$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x00000002 16613385   jbrown    600        1024       0
$ ./consume
Read '42' from shared memory location
$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status  


My guess is that most of that is review for you if you've already been using shared memory but without a working example from you the best I can do is give you minimal working code.


N.B. All error checking has been removed in the above examples for clarity.
Comments on this post
andy101 agrees!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Rebuild and install Shared Library

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap