Jump to content

CreateProcess and hanged program


Recommended Posts

Does anyone have suggestions on why it would be the case that I would call a program using CreateProcess and it (the called program) would not run for about a minute (like above)? I have a WaitForSingleObject call and it seems to be hanging on that in execution...

Link to comment
Share on other sites


While you can use a WaitForSingleOjbect on creation, you might want to investigate WaitForInputIdle instead, as this function will actually wait through the called function's initialization routine, until the called process is idle (waiting for input) - this is "safer" than just an object wait, because if this fails you have chances to do things like break in and dump the called process if it fails to initialize in your try/except blocks or if blocks, which is always nice when debugging.

Link to comment
Share on other sites

While you can use a WaitForSingleOjbect on creation, you might want to investigate WaitForInputIdle instead, as this function will actually wait through the called function's initialization routine,

Isn't WaitForInputIdle used to wait until the process loads, while WaitForSingleObject is used to wait for the process to complete? That was always my understanding (and I use both depending on the flags I pass the routine I use to call other programs)...

Link to comment
Share on other sites

Isn't WaitForInputIdle used to wait until the process loads, while WaitForSingleObject is used to wait for the process to complete? That was always my understanding (and I use both depending on the flags I pass the routine I use to call other programs)...

That is correct - I was assuming you weren't wanting to wait (due to your post about the wait time for the launch), but if you want to return to the caller, you are right :).

Link to comment
Share on other sites

That is correct - I was assuming you weren't wanting to wait (due to your post about the wait time for the launch), but if you want to return to the caller, you are right :).

The problem was that there was a very long time that it would take for the program to even come up (a minute or more). In my testing, the code would be successful to the Wait statement (either one) coded after the CreateProcess, but would hang at the wait statement. If I removed the wait, the program would come up instantaneously. As the original solution post indicated, NT based OSes require the SYNCHRONIZE tag when the process is created if Wait functions are to be used, so that deadlock may not occur (what I was observing), and the problem was solved once that was added to my CreateProcess call.

Thanks for your time! :thumbup

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...