Handle Inheritance in Windows [modified]
-
Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!
modified on Monday, March 21, 2011 7:13 AM
-
Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!
modified on Monday, March 21, 2011 7:13 AM
Look at the documentation for
SetHandleInformation
andDuplicateHandle
.«_Superman_» _I love work. It gives me something to do between weekends.
-
Look at the documentation for
SetHandleInformation
andDuplicateHandle
.«_Superman_» _I love work. It gives me something to do between weekends.
Hi, I know how it is passed. I want to know how to retrieve and use them in child process. An example will help Sudhan
-
Hi, I know how it is passed. I want to know how to retrieve and use them in child process. An example will help Sudhan
-
I had seen this link. I was wondering how to use it for other type of handles (like mutex, sempahore etc, though they can be retrieved through api like OpenMutex) in child process.
-
I had seen this link. I was wondering how to use it for other type of handles (like mutex, sempahore etc, though they can be retrieved through api like OpenMutex) in child process.
-
Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!
modified on Monday, March 21, 2011 7:13 AM
You described how to make the handle available in the child process, but you still need to tell the child the numerical value of the
HANDLE
. A common way of doing this is to pass the value as a command line parameter.--Mike-- Dunder-Mifflin, this is Pam.
-
Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!
modified on Monday, March 21, 2011 7:13 AM
When you create an object (like a mutex) you can specify a "name". (see CreateMutex[^]). In the child process you can retrieve another handle to that same object with OpenMutex[^], or whatever similar and coherent with the type of object) by giving it that name (that is supposed to be unique at least between all your entangled processes). Note that the returned value may be different, due to the fact the the handle value is an "index of a table of indexes" that is different in the various processes. The documentation talks improperly of inheritance of handles. What are inherited are the objects the handle refers to.
2 bugs found. > recompile ... 65534 bugs found. :doh:
-
You described how to make the handle available in the child process, but you still need to tell the child the numerical value of the
HANDLE
. A common way of doing this is to pass the value as a command line parameter.--Mike-- Dunder-Mifflin, this is Pam.
Hi Mike, This is what I was looking for. Handles are copied in the process table of the child process if the inherit flag is set to true but how would the child process know which handle is pointing to which kernel object and which to use. This link [^] explains the concept: "To use a handle, the child process must retrieve the handle value and "know" the object to which it refers. Usually, the parent process communicates this information to the child process through its command line, environment block, or some form of interprocess communication." I was looking for an sample code showing the above step(highlighted in bold).