Home arrow BrainDump arrow Page 4 - The MMAP System Call in Linux

Associated signals - BrainDump

In this third part of a seven-part series on Linux I/O file system calls, you'll learn how to use the mmap() system call, which will give you some flexibility when handling files. This article is excerpted from chapter four of the book Linux System Programming: Talking Directly to the Kernel and C Library, written by Robert Love (O'Reilly, 2007; ISBN: 0596009585). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

TABLE OF CONTENTS:
  1. The MMAP System Call in Linux
  2. The page size
  3. Return values and error codes
  4. Associated signals
By: O'Reilly Media
Rating: starstarstarstarstar / 5
December 11, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Two signals are associated with mapped regions:

SIGBUS

This signal is generated when a process attempts to access a region of a mapping that is no longer valid—for example, because the file was truncated after it was mapped.

SIGSEGV

This signal is generated when a process attempts to write to a region that is mapped read-only.

munmap()

Linux provides the munmap() system call for removing a mapping created with mmap():

 

  #include <sys/mman.h>

  int munmap (void *addr, size_t len);

A call to munmap() removes any mappings that contain pages located anywhere in the process address space starting at addr, which must be page-aligned, and continuing forlenbytes. Once the mapping has been removed, the previously associated memory region is no longer valid, and further access attempts result in aSIGSEGVsignal.

Normally,munmap()is passed the return value and thelenparameter from a previous invocation ofmmap().

On success,munmap()returns0; on failure, it returns
-1, anderrnois set appropriately. The only standarderrnovalue isEINVAL, which specifies that one or more parameters were invalid.

As an example, the following snippet unmaps any memory regions with pages contained in the interval[addr,addr+len]:

  if (munmap (addr, len) == -1)
          perror ("munmap");

Please check back next week for the continuation of this article.



 
 
>>> More BrainDump Articles          >>> More By O'Reilly Media
 

blog comments powered by Disqus
   

BRAINDUMP ARTICLES

- Apple Founder Steve Jobs Dies
- Steve Jobs` Era at Apple Ends
- Google's Chrome Developer Tool Updated
- Google's Chrome 6 Browser Brings Speed to th...
- New Open Source Update Fedora 13 is Released...
- Install Linux with Knoppix
- iPad Developers Flock To SDK 3.2
- Managing a Linux Wireless Access Point
- Maintaining a Linux Wireless Access Point
- Securing a Linux Wireless Access Point
- Configuring a Linux Wireless Access Point
- Building a Linux Wireless Access Point
- Migrating Oracle to PostgreSQL with Enterpri...
- Demystifying SELinux on Kernel 2.6
- Yahoo and Microsoft Create Ad Partnership

Developer Shed Affiliates

 



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

Dev Shed Tutorial Topics: