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-B58D282E-E6EC-4AE1-96DB-30A5FB850563" xml:lang="en"><title><codeph>exec()</codeph> without |
12 <concept id="GUID-B58D282E-E6EC-4AE1-96DB-30A5FB850563" xml:lang="en"><title><codeph>exec()</codeph> without |
13 forking using <apiname>posix_spawn()</apiname></title><prolog><metadata><keywords/></metadata></prolog><conbody> |
13 forking using <codeph>posix_spawn()</codeph></title><prolog><metadata><keywords/></metadata></prolog><conbody> |
14 <p>A UNIX® program may exec without forking. The result is that the calling |
14 <p>A UNIX® program may exec without forking. The result is that the calling |
15 process executes another binary, but inherits certain properties, for example, |
15 process executes another binary, but inherits certain properties, for example, |
16 file descriptors. </p> |
16 file descriptors. </p> |
17 <p>The P.I.P.S. equivalent would be to call <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> and |
17 <p>The P.I.P.S. equivalent would be to call <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> and |
18 pass any inherited data via <codeph>argv</codeph> parameters. </p> |
18 pass any inherited data via <codeph>argv</codeph> parameters. </p> |
19 <p>Note that if a parent process is waiting for the child to terminate then |
19 <p>Note that if a parent process is waiting for the child to terminate then |
20 the termination of the newly created task must be synchronised. Therefore |
20 the termination of the newly created task must be synchronised. Therefore |
21 a <xref href="GUID-8F5C89A4-7813-32C7-973E-F7F0F3690BC6.dita"><apiname>waitpid()</apiname></xref> call should follow the <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> call |
21 a <xref href="GUID-8F5C89A4-7813-32C7-973E-F7F0F3690BC6.dita"><apiname>waitpid()</apiname></xref> call should follow the <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> call |
22 so that it does not exit prematurely. Otherwise <xref href="GUID-FED685F4-5FAD-39F4-9812-3B0A85D8718C.dita"><apiname>exit()</apiname></xref> can |
22 so that it does not exit prematurely. Otherwise <xref href="GUID-FED685F4-5FAD-39F4-9812-3B0A85D8718C.dita"><apiname>exit()</apiname></xref> can |
23 be called after the posix_spawn(). </p> |
23 be called after the posix_spawn(). </p> |
24 <p>Also, note that if the process which formerly executed and |
24 <p>Also, note that if the process which formerly executed and which now uses <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> stores |
25 which now uses <xref href="GUID-E7C4DE71-BC5B-34AE-ACB3-C34A0DB1FC16.dita"><apiname>posix_spawn()</apiname></xref> stores its PID (for example, |
25 its PID (for example, in the file system) to allow other processes to target |
26 in the file system) to allow other processes to target it, then care must |
26 it, then care must be taken to store the relevant PID (Process ID). This is |
27 be taken to store the relevant PID (Process ID). This is because the PID for |
27 because the PID for the newly spawned process may need to be stored instead.</p> |
28 the newly spawned process may need to be stored instead.</p> |
|
29 </conbody></concept> |
28 </conbody></concept> |