| <html lang="en"> |
| <head> |
| <title>Process Creation Concepts - The GNU C Library</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="The GNU C Library"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Processes.html#Processes" title="Processes"> |
| <link rel="prev" href="Running-a-Command.html#Running-a-Command" title="Running a Command"> |
| <link rel="next" href="Process-Identification.html#Process-Identification" title="Process Identification"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| This file documents the GNU C library. |
| |
| This is Edition 0.12, last updated 2007-10-27, |
| of `The GNU C Library Reference Manual', for version |
| 2.8 (Sourcery G++ Lite 2011.03-41). |
| |
| Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, |
| 2003, 2007, 2008, 2010 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software Needs Free Documentation'' |
| and ``GNU Lesser General Public License'', the Front-Cover texts being |
| ``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A |
| copy of the license is included in the section entitled "GNU Free |
| Documentation License". |
| |
| (a) The FSF's Back-Cover Text is: ``You have the freedom to |
| copy and modify this GNU manual. Buying copies from the FSF |
| supports it in developing GNU and promoting software freedom.''--> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| <link rel="stylesheet" type="text/css" href="../cs.css"> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Process-Creation-Concepts"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="Process-Identification.html#Process-Identification">Process Identification</a>, |
| Previous: <a rel="previous" accesskey="p" href="Running-a-Command.html#Running-a-Command">Running a Command</a>, |
| Up: <a rel="up" accesskey="u" href="Processes.html#Processes">Processes</a> |
| <hr> |
| </div> |
| |
| <h3 class="section">26.2 Process Creation Concepts</h3> |
| |
| <p>This section gives an overview of processes and of the steps involved in |
| creating a process and making it run another program. |
| |
| <p><a name="index-process-ID-3154"></a><a name="index-process-lifetime-3155"></a>Each process is named by a <dfn>process ID</dfn> number. A unique process ID |
| is allocated to each process when it is created. The <dfn>lifetime</dfn> of |
| a process ends when its termination is reported to its parent process; |
| at that time, all of the process resources, including its process ID, |
| are freed. |
| |
| <p><a name="index-creating-a-process-3156"></a><a name="index-forking-a-process-3157"></a><a name="index-child-process-3158"></a><a name="index-parent-process-3159"></a>Processes are created with the <code>fork</code> system call (so the operation |
| of creating a new process is sometimes called <dfn>forking</dfn> a process). |
| The <dfn>child process</dfn> created by <code>fork</code> is a copy of the original |
| <dfn>parent process</dfn>, except that it has its own process ID. |
| |
| <p>After forking a child process, both the parent and child processes |
| continue to execute normally. If you want your program to wait for a |
| child process to finish executing before continuing, you must do this |
| explicitly after the fork operation, by calling <code>wait</code> or |
| <code>waitpid</code> (see <a href="Process-Completion.html#Process-Completion">Process Completion</a>). These functions give you |
| limited information about why the child terminated—for example, its |
| exit status code. |
| |
| <p>A newly forked child process continues to execute the same program as |
| its parent process, at the point where the <code>fork</code> call returns. |
| You can use the return value from <code>fork</code> to tell whether the program |
| is running in the parent process or the child. |
| |
| <p><a name="index-process-image-3160"></a>Having several processes run the same program is only occasionally |
| useful. But the child can execute another program using one of the |
| <code>exec</code> functions; see <a href="Executing-a-File.html#Executing-a-File">Executing a File</a>. The program that the |
| process is executing is called its <dfn>process image</dfn>. Starting |
| execution of a new program causes the process to forget all about its |
| previous process image; when the new program exits, the process exits |
| too, instead of returning to the previous process image. |
| |
| </body></html> |
| |