1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Program for shared memory in c++

Discussion in 'C++' started by bashamsc, Jan 25, 2008.

  1. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Even I did the same and so we would like to make sure we conclude that its an original contribution.
     
  2. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    See to understand the program first u need to have an idea of shared memory.

    Shared memory comes under Inter-Process Communication.

    Shared memory is the fastest of all IPC.

    Shared memory comes under System V IPC.

    SHARED MEMORY:

    Shared memory is one of the three System V IPC.

    It allows two unrelated processes to access the same logical memory.

    Shared memory is a very efficient way of transferring data between two running processes.


    In the program i have used these functions.

    shmget and shmat for shared memory.

    shmget is used to create shared memory.

    shmat is used to attach the shared memory to the address space of the process.

    When we come to the program,i have created two process i.e process-1 and process-2.

    process-1 and process-2 uses same memory i.e shared memory.

    I have created a single bit shared memory to control the two process not to access the shared memory at a time.

    When process-1 uses the shared memory then process-2 waits until process-1 completes its work and wise versa .

    Run the two process at a time (i.e in two terminals ) and u will observe that When process-1 uses the shared memory then process-2 waits until process-1 completes its work and wise versa .
     
    Last edited: Feb 26, 2008
  3. imrantechi

    imrantechi New Member

    Joined:
    Feb 12, 2008
    Messages:
    116
    Likes Received:
    4
    Trophy Points:
    0
    Okay!!! Thanks man...
     
  4. debleena_doll2002

    debleena_doll2002 New Member

    Joined:
    Feb 5, 2008
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    0
    Leave it bashamsc !!! your effort is really apprecited. Now please dont make issue more. That article should be nominated!!! Finallllll
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
  6. lead.smart34

    lead.smart34 New Member

    Joined:
    Feb 14, 2008
    Messages:
    77
    Likes Received:
    0
    Trophy Points:
    0
  7. crazytolearn57

    crazytolearn57 New Member

    Joined:
    Feb 14, 2008
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    0
    what is this problem of copy
     
  8. rlearntowin1

    rlearntowin1 New Member

    Joined:
    Feb 26, 2008
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
  9. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
  11. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
  12. aisha.ansari84

    aisha.ansari84 New Member

    Joined:
    Feb 13, 2008
    Messages:
    82
    Likes Received:
    1
    Trophy Points:
    0
    congrats you won
     
  13. sorabh284

    sorabh284 New Member

    Joined:
    Mar 25, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    when we pass object as argument to a function, then whether constructor or destructor are called or not.
     
  14. Mufasa

    Mufasa New Member

    Joined:
    Jul 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Germany
    Hi @all,

    ok this thread is a bit old already.... but I'm working on quite the same issue now so I thought I refresh this instead of starting a new...

    1st: Big thanks to bashamsc for this great code!!

    Now what I am trying to do for a while now.... ( without any success until now :( ) is to access this SHM with PHP. So I have a shared-memory created with C++ and I want to read and change the data inside with PHP and read with C++ again and so on...... U know what I mean? I know a bit difficult to explain....

    Allright, I know how to create a shm with php and write data inside..... but how the h*** can I access this C++ created shm??

    Appreciate every help or suggestion.

    Thanks in advance & regards from Germany :)
     
  15. banty_raju123

    banty_raju123 New Member

    Joined:
    Jul 29, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    ur information is very useful for me thankx
     

Share This Page