I'm currently passing the pid on the command line to the child, but is there a way to do this in the Win32 API? Alternatively, can someone alleviate my fear that the pid I'm passing might belong to another process after some time if the parent has died?
相关问题
- the application was unable to start correctly 0xc0
- how to get running process information in java?
- Handle button click in another application
- Stop child process when parent process stops
- Program doesn’t terminate when using processes
相关文章
- Why windows 64 still makes use of user32.dll etc?
- How to start a process in its own process group?
- Can WM_NEXTDLGCTL be used with non-dialog windows?
- Windows EventLog: How fast are operations with it?
- Are resource files compiled as UNICODE or ANSI cod
- user32 and kernel method list for C# [closed]
- How to redirect child process stdout/stderr to the
- Writing to the middle of the file (without ove
A better way to do this is to call
DuplicateHandle()
to create an inheritable duplicate of your process handle. Then create the child process and pass the handle value on the command line.Close
the duplicated handle in the parent process. When the child's done, it will need toClose
its copy as well.Notice that if the parent process terminates it is very possible and even likely that the PID will be reused for another process. This is standard windows operation.
So to be sure, once you receive the id of the parent and are sure it is really your parent you should open a handle to it and use that.
Yes, the PID can be reused. Unlike UNIX, Windows does not maintain a strong parent-child relationship tree.
Just in case anyone else runs across this question and is looking for a code sample, I had to do this recently for a Python library project I'm working on. Here's the test/sample code I came up with: