Symbian3/SDK/Source/GUID-4AEBF49C-E62A-5D0D-8181-600BF29DFFC7.dita
changeset 13 48780e181b38
parent 7 51a74ef9ed63
equal deleted inserted replaced
12:80ef3a206772 13:48780e181b38
     7     Nokia Corporation - initial contribution.
     7     Nokia Corporation - initial contribution.
     8 Contributors: 
     8 Contributors: 
     9 -->
     9 -->
    10 <!DOCTYPE concept
    10 <!DOCTYPE concept
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    12 <concept id="GUID-4AEBF49C-E62A-5D0D-8181-600BF29DFFC7" xml:lang="en"><title>IPC:
    12 <concept id="GUID-4AEBF49C-E62A-5D0D-8181-600BF29DFFC7" xml:lang="en"><title>IPC: IPC Mechanisms</title><prolog><metadata><keywords/></metadata></prolog><conbody>
    13 IPC Mechanisms</title><prolog><metadata><keywords/></metadata></prolog><conbody>
    13 <p>This example demonstrates how a parent process communicates with
    14 <p>This example demonstrates how a parent process communicates with its child
    14 its child process using various IPC mechanisms. Two executables, a
    15 process using various IPC mechanisms. Two executables, a parent and a child
    15 parent and a child (spawned by the parent) are created to demonstrate
    16 (spawned by the parent) are created to demonstrate these mechanisms. The child
    16 these mechanisms. The child process is created by the parent using
    17 process is created by the parent using the <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> function.
    17 the <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> function. The parent process
    18 The parent process communicates with the child process using the following
    18 communicates with the child process using the following IPC mechanisms: </p>
    19 IPC mechanisms: </p>
       
    20 <ul>
    19 <ul>
    21 <li id="GUID-D1CABBD1-AC3A-5216-B2A6-D860C876DEDE"><p>Named pipes (FIFO -
    20 <li id="GUID-D1CABBD1-AC3A-5216-B2A6-D860C876DEDE"><p>Named pipes
    22 First in First Out) </p> </li>
    21 (FIFO - 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
    22 <li id="GUID-8FE87BCB-200D-5498-8F1A-851B861F8673"><p>Single pipe
    24 call) </p> </li>
    23 (<xref href="GUID-A9DB6E7C-B8D6-377A-BBE6-39E0A7A09E5D.dita"><apiname>popen()</apiname></xref> system call) </p> </li>
    25 </ul>
    24 </ul>
    26 <section id="GUID-E584CAE4-BC05-48D5-837C-40B73DD4524F"><title>Download</title><p>Click on the following link to download
    25 <section id="GUID-E584CAE4-BC05-48D5-837C-40B73DD4524F"><title>Download</title><p>Click on the following link to download 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>
    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>
    26 <section id="GUID-5513D686-D38A-49A9-B3B2-2259992A69A8"><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 creates the child process. A pointer to the process ID
    28 <section id="GUID-5513D686-D38A-49A9-B3B2-2259992A69A8"><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
    27 (<codeph>pid</codeph>) of the child process and the path of the child
    29 creates the child process. A pointer to the process ID (<codeph>pid</codeph>)
    28 process are passed as arguments to this function. The parent waits
    30 of the child process and the path of the child process are passed as arguments
    29 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 a named pipe</b> </p> <p>This example
    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
    30 creates a named pipe using the <xref href="GUID-F4749DAA-1B29-3D1D-A3AA-0D52B851E501.dita"><apiname>mkfifo()</apiname></xref> function.
    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.
    31 The child writes data into the FIFO and then exits. The parent reads
    33 The child writes data into the FIFO and then exits. The parent reads data
    32 data from FIFO and writes it to the console. The first argument of
    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
    33 the <xref href="GUID-F4749DAA-1B29-3D1D-A3AA-0D52B851E501.dita"><apiname>mkfifo()</apiname></xref> function indicates the path of the
    35 indicates the path of the FIFO file. </p> <p><b> Opening a single pipe</b> </p> <p>The
    34 FIFO file. </p> <p><b> Opening a single pipe</b> </p> <p>The parent
    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.
    35 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. A file handle to the pipe is returned
    37 A file handle to the pipe is returned to the parent and the parent uses this
    36 to the parent and the parent uses this handle to read the data written
    38 handle to read the data written to the pipe by the child. The path of the
    37 to the pipe by the child. The path of the child process is passed
    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>
    38 as the first argument to the <xref href="GUID-A9DB6E7C-B8D6-377A-BBE6-39E0A7A09E5D.dita"><apiname>popen()</apiname></xref> function. </p> </section>
    40 <section id="GUID-367A6465-F1C3-46B3-820B-7086E0BE1BEB"><title>Build</title> <p>The following statements are present in all
    39 <section id="GUID-367A6465-F1C3-46B3-820B-7086E0BE1BEB"><title>Build</title> <p>The following statements are present in all the <filepath>.mmp</filepath> files of the example: </p> <codeblock id="GUID-09782F92-8B25-5CF5-8027-599685F5726D" xml:space="preserve">SYSTEMINCLUDE epoc32\include\stdapis
    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
    40 LIBRARY libc.lib
    43 STATICLIBRARY libcrt0.lib</codeblock> <p> <b>Note:</b> You require these statements
    41 STATICLIBRARY libcrt0.lib</codeblock> <p> <b>Note:</b> You require
    44 because of the following reasons: </p> <ul>
    42 these statements because of the following reasons: </p> <ul>
    45 <li id="GUID-C735ED4D-4FDD-5535-ACA2-C645C3F10762"><p>The <filepath>epoc32\include\stdapis</filepath> directory
    43 <li id="GUID-C735ED4D-4FDD-5535-ACA2-C645C3F10762"><p>The <filepath>epoc32\include\stdapis</filepath> directory contains header files
    46 contains header files such as, <filepath>stdio.h</filepath>, <filepath>unistd.h</filepath> and
    44 such as, <filepath>stdio.h</filepath>, <filepath>unistd.h</filepath> and so on that are required to build an Open Environment application. </p> </li>
    47 so on that are required to build an Open Environment application. </p> </li>
    45 <li id="GUID-6351CD50-ED02-5DC9-BAAF-971CB92EEAD3"><p>The <filepath>libc.lib</filepath> file contains the definitions of all functions
    48 <li id="GUID-6351CD50-ED02-5DC9-BAAF-971CB92EEAD3"><p>The <filepath>libc.lib</filepath> file
    46 that are defined in the header files associated with this example. </p> </li>
    49 contains the definitions of all functions that are defined in the header files
    47 <li id="GUID-C7A1D9C5-07E6-5FD1-B770-24180F04623A"><p>The <filepath>libcrt0.lib</filepath> file provides the <codeph>E32Main()</codeph> function, which is the entry point for the <codeph>main()</codeph> function of the example. </p> </li>
    50 associated with this example. </p> </li>
    48 </ul> <p> The <codeph>IPC</codeph> builds the following binaries in
    51 <li id="GUID-C7A1D9C5-07E6-5FD1-B770-24180F04623A"><p>The <filepath>libcrt0.lib</filepath> file
    49 the standard location (<filepath>\epoc32\release\winscw\&lt;build_variant&gt;</filepath> for Carbide.c++). </p> <ul>
    52 provides the <codeph>E32Main()</codeph> function, which is the entry point
    50 <li id="GUID-1F256024-8210-5C50-8B18-0498C0D5C15F"><p> <b>ipcparent.exe:</b> Executable of the parent process. </p> </li>
    53 for the <codeph>main()</codeph> function of the example. </p> </li>
    51 <li id="GUID-1C755509-96FA-510A-944B-3FEA065C9936"><p> <b>ipcchild.exe:</b> Executable of the child process created using the <xref href="GUID-A9DB6E7C-B8D6-377A-BBE6-39E0A7A09E5D.dita"><apiname>popen()</apiname></xref> function. </p> </li>
    54 </ul> <p> <xref href="GUID-3100800B-B2F7-50EF-BD4C-3C345ECCB2A5.dita">The Symbian
    52 <li id="GUID-C056BC80-D664-5F25-A730-35220CA0A6B5"><p> <b>fifochild.exe:</b> Executable of the child process created using the <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> function. </p> </li>
    55 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>
    53 </ul> </section>
    65 <section id="GUID-9F7DC4C5-16C8-4223-80E0-19DDF9E8303E"><title>Runtime setting</title> <p>Two eshells must be opened before
    54 <section id="GUID-9F7DC4C5-16C8-4223-80E0-19DDF9E8303E"><title>Runtime
    66 executing this example. The executable, <filepath>ipcparent.exe</filepath> is
    55 setting</title> <p>Two eshells must be opened before executing this
    67 run in one eshell and the other eshell is used to run the child process <filepath>fifochild.exe</filepath>.
    56 example. The executable, <filepath>ipcparent.exe</filepath> is run
    68 You can switch between the two eshells by pressing <b>CTRL</b> +<b>ALT</b> +<b>SHIFT</b> +<b>T</b>. </p> </section>
    57 in one eshell and the other eshell is used to run the child process <filepath>fifochild.exe</filepath>. You can switch between the two eshells
       
    58 by pressing <b>CTRL</b> +<b>ALT</b> +<b>SHIFT</b> +<b>T</b>. </p> </section>
    69 </conbody></concept>
    59 </conbody></concept>