[LCP] creating a file descriptor entry for a piece of memory

David Nugent davidn at datalinktech.com.au
Mon Nov 10 19:57:24 EST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/11/2008, at 12:42 PM, Mark Farnell wrote:

> So do you reckon the best way is to use shm_open?

Since I don't know what problem you're trying to solve, I can't offer  
any useful advice there. It just seems that you seem more stuck on the  
implementation details than focusing on the problem you're trying to  
solve.

What advice I will offer, though, is not to implement an idea because  
that's how you think it should be done. Instead, look around at how  
others others have solved the same or similar problems and learn to  
recognise and understand the underlying /design pattern/ involved and  
how well it provides the solution to that class of problem, which will  
allow you to take advantage of possibly years of experience, trial and  
error. You can learn a lot very quickly this way instead of being  
caught up in the intricacies of implementing something you don't quite  
understand.

This is not to say that your approach is wrong, but at least you could  
avoid uselessly reinventing a wheel where an already known and trusted  
wheel will work just fine. The art of computer programming often comes  
down to recognising where and when to apply existing and well known  
design patterns.


> If the process crashes before calling shm_unlink(), you told me that
> shared memory will be freed.  However will the entry under /dev/shm
> stay?

/dev/shm is, in this case, a kernel filesystem, like procfs and sysfs.  
It does not exist on disk. It simply reflects data that is present in  
the running kernel. So if the kernel dumps it (and indeed it does free  
unreferenced shared memory), it will disappear from that filesystem  
also.

These kernel filesystems represent a safer, more sane way of accessing  
kernel structures where previously in Unix a decade or two ago you  
would have to open(2) /dev/kmem or equivalent (which is essentially a  
memory map of the running kernel) and poke about in there to obtain  
the same information, with all that implies regarding abi  
compatibility and the security of information contained in kernel  
memory.


Regards,
- --
David Nugent (davidn at datalinktech.com.au)
Software Engineer,
Datalink Technologies Pty Ltd
Mobile GPS/GPRS Business Solutions

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAkkX93QACgkQgyBtWyGDJqW+BACfd1146hdlyR12VY9i01AIdK/U
NzQAnA1zHwc51L8+RCLEJSPg4jmlk6bB
=aavr
-----END PGP SIGNATURE-----



More information about the linuxCprogramming mailing list