Re: mmap & MAP_ANON/MAP_PRIVATE/MAP_SHARED
Gerd Knorr (kraxel@goldbach.isdn.cs.tu-berlin.de)
Fri, 19 Sep 1997 22:39:24 +0200
In article <34228FB4.167E@algorithmics.com>, you wrote:
>Andrew Pollard wrote:
>>
>> Hello,
>>
>> I wonder if anyone can tell me whether Linux (2.0.31pre9 and 2.1.55)
>> should handle mmap with MAP_ANON|MAP_SHARED as an argument?
>
>I'm interested in the EXACT SAME THING!! This beats the pants out of
>shmget() since anonymous memory gets cleaned up automatically after
>coring! (I know, apps are NOT supposed to core dump, but this isn't a
>perfect world and some ayaadmin's don't both checking servr conditions
>regularily!)
Just do
shm_id = shmget(IPC_PRIVATE, size, IPC_CREAT | 0700);
shm_addr = shmat(shm_id, 0, 0);
shmctl(shm_id, IPC_RMID, 0);
and you are fine. shmdt(), exit() or a coredump will cleanup the
shared memory segment.
Gerd
--
Never check for a error condition you don't know how to handle.