Symbian3/SDK/Source/GUID-4AEBF49C-E62A-5D0D-8181-600BF29DFFC7.dita
changeset 0 89d6a7a84779
equal deleted inserted replaced
-1:000000000000 0:89d6a7a84779
       
     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 id="GUID-4AEBF49C-E62A-5D0D-8181-600BF29DFFC7" xml:lang="en"><title>IPC:
       
    13 IPC Mechanisms</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>This example demonstrates how a parent process communicates with its child
       
    15 process using various IPC mechanisms. Two executables, a parent and a child
       
    16 (spawned by the parent) are created to demonstrate these mechanisms. The child
       
    17 process is created by the parent using the <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> function.
       
    18 The parent process communicates with the child process using the following
       
    19 IPC mechanisms: </p>
       
    20 <ul>
       
    21 <li id="GUID-D1CABBD1-AC3A-5216-B2A6-D860C876DEDE"><p>Named pipes (FIFO -
       
    22 First in First Out) </p> </li>
       
    23 <li id="GUID-8FE87BCB-200D-5498-8F1A-851B861F8673"><p>Single pipe (<xref href="GUID-A9DB6E7C-B8D6-377A-BBE6-39E0A7A09E5D.dita"><apiname>popen()</apiname></xref> system
       
    24 call) </p> </li>
       
    25 </ul>
       
    26 <section><title>Download</title><p>Click on the following link to download
       
    27 the example: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/zips/guid-c5b6ac05-a3fb-45df-ab11-bd8ccc13537f.zip" scope="external">IPC.zip</xref></p><p>Click: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/guid-c5b6ac05-a3fb-45df-ab11-bd8ccc13537f.html" scope="peer">browse</xref> to view the example code. </p> </section>
       
    28 <section><title>Description</title> <p><b> Spawning the child process</b> </p> <p>The <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> function
       
    29 creates the child process. A pointer to the process ID (<codeph>pid</codeph>)
       
    30 of the child process and the path of the child process are passed as arguments
       
    31 to this function. The parent waits for the child to terminate by calling the <xref href="GUID-8F5C89A4-7813-32C7-973E-F7F0F3690BC6.dita"><apiname>waitpid()</apiname></xref> function. </p> <p><b> Creating
       
    32 a named pipe</b> </p> <p>This example creates a named pipe using the <xref href="GUID-F4749DAA-1B29-3D1D-A3AA-0D52B851E501.dita"><apiname>mkfifo()</apiname></xref> function.
       
    33 The child writes data into the FIFO and then exits. The parent reads data
       
    34 from FIFO and writes it to the console. The first argument of the <xref href="GUID-F4749DAA-1B29-3D1D-A3AA-0D52B851E501.dita"><apiname>mkfifo()</apiname></xref> function
       
    35 indicates the path of the FIFO file. </p> <p><b> Opening a single pipe</b> </p> <p>The
       
    36 parent creates a child process and a pipe to the child process using the <xref href="GUID-A9DB6E7C-B8D6-377A-BBE6-39E0A7A09E5D.dita"><apiname>popen()</apiname></xref> function.
       
    37 A file handle to the pipe is returned to the parent and the parent uses this
       
    38 handle to read the data written to the pipe by the child. The path of the
       
    39 child process is passed as the first argument to the <xref href="GUID-A9DB6E7C-B8D6-377A-BBE6-39E0A7A09E5D.dita"><apiname>popen()</apiname></xref> function. </p> </section>
       
    40 <section><title>Build</title> <p>The following statements are present in all
       
    41 the <filepath>.mmp</filepath> files of the example: </p> <codeblock id="GUID-09782F92-8B25-5CF5-8027-599685F5726D" xml:space="preserve">SYSTEMINCLUDE epoc32\include\stdapis
       
    42 LIBRARY libc.lib
       
    43 STATICLIBRARY libcrt0.lib</codeblock> <p> <b>Note:</b> You require these statements
       
    44 because of the following reasons: </p> <ul>
       
    45 <li id="GUID-C735ED4D-4FDD-5535-ACA2-C645C3F10762"><p>The <filepath>epoc32\include\stdapis</filepath> directory
       
    46 contains header files such as, <filepath>stdio.h</filepath>, <filepath>unistd.h</filepath> and
       
    47 so on that are required to build an Open Environment application. </p> </li>
       
    48 <li id="GUID-6351CD50-ED02-5DC9-BAAF-971CB92EEAD3"><p>The <filepath>libc.lib</filepath> file
       
    49 contains the definitions of all functions that are defined in the header files
       
    50 associated with this example. </p> </li>
       
    51 <li id="GUID-C7A1D9C5-07E6-5FD1-B770-24180F04623A"><p>The <filepath>libcrt0.lib</filepath> file
       
    52 provides the <codeph>E32Main()</codeph> function, which is the entry point
       
    53 for the <codeph>main()</codeph> function of the example. </p> </li>
       
    54 </ul> <p> <xref href="GUID-3100800B-B2F7-50EF-BD4C-3C345ECCB2A5.dita">The Symbian
       
    55 OS build process</xref> describes how to build this example. The <codeph>IPC</codeph> builds
       
    56 the following binaries in the standard location (<filepath>\epoc32\release\winscw\&lt;build_variant&gt;</filepath> for
       
    57 Carbide.c++). </p> <ul>
       
    58 <li id="GUID-1F256024-8210-5C50-8B18-0498C0D5C15F"><p> <b>ipcparent.exe:</b> Executable
       
    59 of the parent process. </p> </li>
       
    60 <li id="GUID-1C755509-96FA-510A-944B-3FEA065C9936"><p> <b>ipcchild.exe:</b> Executable
       
    61 of the child process created using the <xref href="GUID-A9DB6E7C-B8D6-377A-BBE6-39E0A7A09E5D.dita"><apiname>popen()</apiname></xref> function. </p> </li>
       
    62 <li id="GUID-C056BC80-D664-5F25-A730-35220CA0A6B5"><p> <b>fifochild.exe:</b> Executable
       
    63 of the child process created using the <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> function. </p> </li>
       
    64 </ul> </section>
       
    65 <section><title>Runtime setting</title> <p>Two eshells must be opened before
       
    66 executing this example. The executable, <filepath>ipcparent.exe</filepath> is
       
    67 run in one eshell and the other eshell is used to run the child process <filepath>fifochild.exe</filepath>.
       
    68 You can switch between the two eshells by pressing <b>CTRL</b> +<b>ALT</b> +<b>SHIFT</b> +<b>T</b>. </p> </section>
       
    69 </conbody></concept>