A child process can inherit the following properties and resources of its parent:
Open handles that were opened with the inherit flag set to TRUE. The functions that create or open object handles (CreateFile, CreateMutex, CreateSemaphore, CreateEvent, CreateProcess, CreateThread, CreateConsoleScreenBuffer, CreateFileMapping, CreatePipe, CreateNamedPipe, . . . ) take a security attributes argument that includes this inherit flag
Environment variables
Current directory
For console apps, the input and output buffers, i.e, StdIn and StdOut.
It is also possible to prevent a child process from inheriting any or all of the objects and properties listed above. To prevent the child process from inheriting the environment variables or current directory of its parent, simply specify the desired environment or directory in the corresponding CreateProcess parameter.
CreateProcess has a flag that can be set to FALSE if you do not want the child process to inherit any handles. To have some handles inherited while others are not, use the security attributes argument in any of the calls that open or create an inheritable handle. If the security attributes argument is omitted (NULL) or if its bInheritHandle flag is FALSE, the handle will not be inherited. If a process has an inheritable open handle that you do not want to be inherited by the child process, use DuplicateHandle to open a non-inheritable duplicate of the handle, and then use CloseHandle to close the inheritable handle. The same calls can be used to open an inheritable duplicate of a non-inheritable handle.
Inherited handles appear in the handle table of the child process, which allows the child to access the objects to which the handles refer. But to use a handle, the child needs to retrieve the handle and know the object to which it refers. For most handles, the parent process will need to communicate this information to the child. This can be done using the command line, or any of the methods for interprocess communication (pipes, shared memory).
A handle inherited by a child process refers to the same object and has the same access privileges as the parent's handle. When one process changes the state of the object, both processes will see the change. With file handles, for example, if one process uses a handle to read from a file, the current file position will be moved for all processes using the same handle. As another example, if a child process changes the state of the console that it inherited from its parent, such as changing the mode or the text attributes, the changes will be seen by the parent process.
The child process does not inherit:
Priority class
Memory handles
GDI handles, such as HMENU, HBITMAP, . . . Note that these handles refer to global objects that are in system memory, which means that given a handle as an identifier a child process can access an HMENU created by its parent. But when the parent goes away, the handle becomes invalid. Using such an invalid handle by a child process can bring down the system.