Re: A shared library which attaches a shared segment - what's the right way??

From: Paul Pluzhnikov (ppluzhnikov-nsp_at_charter.net)
Date: 12/25/04

  • Next message: RickE: "Re: How to gain access to my 7043-140 ? :-("
    Date: 25 Dec 2004 13:51:53 -0800
    
    

    "Boaz" <boazter@hotmail.com> writes:

    > I wrote a shared memory library in c++ which using 'shmget' and 'shmat'
    > to allocate a shared memory segment.
    > The varibale which attaches the shared memory segment using 'shmat' is
    > defined static.
    > I have two questions:
    > Since the latrer variable is static, is it possible for each process
    > which links this lobrary, to use this shared segment?

    The visibilty of the variable has *absolutely* nothing to do with
    whether the processes can use this shared memory.

    You continue to demonstrate complete lack of understanding of how
    UNIX virtual memory works. I advise you (for the last time) to read
    an introductory book on the subject.

    > If i want to remove this shared segment from memory, do i need to use
    > both 'shmdt' and 'shmctl', or only 'shmctl'?

    Remove this segment from memory of the process? Use shmdt.

    Remove it from the system (so no other process can attach to it)?
    Use shmctl(..., IPC_RMID).

    Note that the segment will not be actually destroyed until last
    attached process exits or performs shmdt.

    Cheers,

    -- 
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.
    

  • Next message: RickE: "Re: How to gain access to my 7043-140 ? :-("

    Relevant Pages

    • Problems accessing shared memory
      ... create or access the shared memory segment on a specific computer. ... The problem also appeared on a system using Windows 2003 server and Windows ... but we found a fix. ...
      (microsoft.public.dotnet.framework.interop)
    • Re: Argument shmaddr in shmat()
      ... void *shmat(int shmid, void *shmaddr, int shmflg); ... If the shared memory segment has never been attached to by any ... Does it mean that if the only process works with the shared memory ... segment, then shmaddr must be set 0 in shmat(), i.e. ...
      (comp.sys.hp.hpux)
    • Re: Argument shmaddr in shmat()
      ... segment, then shmaddr must be set 0 in shmat(), i.e. ... and attaches a shared memory segment -- yes, ...
      (comp.sys.hp.hpux)
    • Re: Quick questions on Shared Memory
      ... Andrew Falanga wrote: ... I finally got my shared memory program to work. ... > system destroys the shared memory segment. ... > Then a second program access the segment and reads the values. ...
      (comp.unix.programmer)
    • Re: [patch 4/4] Cleanup file_count usage: Avoid file_count usage for hugetlb nattach reporting
      ... > sysv style shared memory segment, seems to work although it looks bogus ... > for shm hugetlb attaches. ... > lines as in regular sysv shared memory segments. ...
      (Linux-Kernel)