|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept xml:lang="en" id="GUID-BE70DCBF-366A-5054-B0F1-7FCEF45FC735"><title>Creating and Unlinking a File Descriptor from a Shared Memory</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>The <xref href="GUID-FF8FD54D-4CD3-3DC7-9A48-56043F26E5DD.dita"><apiname>shm_open()</apiname></xref> function enables you to create shared memory and associate a file descriptor. Use the <xref href="GUID-BF359599-0088-3F3E-BD80-B09C1F5DA380.dita"><apiname>shm_unlink()</apiname></xref> function to remove (unlink a file descriptor from a shared memory) the name of the shared memory object. </p> <p>Example: </p> <codeblock id="GUID-F030E460-536D-53A8-86F1-36E63860677D" xml:space="preserve">#include <stdio.h> |
|
13 #include <sys/mman.h> |
|
14 #include <fcntl.h> |
|
15 #include <errno.h> |
|
16 int main(void) |
|
17 { |
|
18 int fd;// File Descriptor |
|
19 int ret; |
|
20 if((fd = shm_open("page", O_RDWR|O_CREAT, 0666)) < 0) |
|
21 { |
|
22 printf("Shared memory creation failed with errno %d\n", errno); |
|
23 } |
|
24 else |
|
25 { |
|
26 printf("Shared memory creation was successful\n"); |
|
27 } |
|
28 close(fd);//closing the file descriptor |
|
29 if((ret = shm_unlink("page")) < 0) |
|
30 { |
|
31 printf("Shared memory unlinking failed with errno %d\n", errno); |
|
32 } |
|
33 else |
|
34 { |
|
35 printf("Shared memory unlinking was successful\n"); |
|
36 } |
|
37 return ret; |
|
38 }</codeblock> </conbody><related-links><link href="GUID-9AC6774A-41E9-5298-8696-0A317A09E1E9.dita"><linktext>Librt Overview</linktext> </link> <link href="GUID-A4ECB450-02DA-5E85-91AC-4C8BDE0B9B58.dita"><linktext>Writing, Reading and Seeking from a |
|
39 Shared Memory</linktext> </link> <link href="GUID-8F6D6934-8FF0-5045-8AB1-74384BE792EA.dita"><linktext>Retrieving Information about a |
|
40 Shared Memory Object</linktext> </link> <link href="GUID-66402932-5C44-556B-A7AC-1C2D245C8B05.dita"><linktext>Clocks and Timers Tutorial</linktext> </link> </related-links></concept> |