Thread: urgent doubt in windows programming, please help me

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    Thumbs up urgent doubt in windows programming, please help me

    The below code when run, assuming necessary header files will give following output?

    Code:
    HANDLE hProcess = CreateProcess(..);
    WaitForSingleObject(hProcess, INFINITE);
    a) wait for I/O
    b) scheduled
    c)finished executed
    d)wait infinite

    I guess it won't wait here....what do you think?

  2. #2
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    i guess timeout won't happen here since its INFINITE...pls help me?

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    the logic of the code snippet is all wrong. CreateProcess does not return a HANDLE. it returns a BOOL value indicating success or failure. the handle comes from the process structure you pass to CreateProcess. if CreateProcess is successful, you will be waiting on a handle of some undefined, nonzero value, which is of no relevance to the process you created. if CreateProcess fails, you'll be waiting on the "System Idle Process," which will likely block forever. you may be correct in thinking it won't return, but you also may be wrong, depending on the result of CreateProcess. therefore the behavior of your program here is undefined.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    do you mean answer is d) and it waits infinite...i thought it was c) as it will not wait and finishes execution

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    Thumbs up

    Quote Originally Posted by leo2008 View Post
    do you mean answer is d) and it waits infinite...i thought it was c) as it will not wait and finishes execution
    for the above code, until when will "wait" happen for hProcess?

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    did you even read my response?

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    yes read your response, but am confused still...can you be clear whether wait happens infinitely here?

  8. #8
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Er... moderators?

    Four random spammed multiple choice questions obviously from some sort of test with no effort to try to answer the question / justify their answer themselves and couldn't even keep them in the same thread?

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by leo2008 View Post
    yes read your response, but am confused still...can you be clear whether wait happens infinitely here?
    it might, or it might not. like I said, the behavior of this program is undefined.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in win32 c++ code , please urgent help needed
    By leo2008 in forum Windows Programming
    Replies: 7
    Last Post: 03-17-2013, 10:47 PM
  2. doubt in c++ code, urgent please
    By leo2008 in forum C++ Programming
    Replies: 24
    Last Post: 03-13-2013, 02:43 AM
  3. doubt regarding GAME Programming
    By satyam in forum Game Programming
    Replies: 10
    Last Post: 01-22-2012, 12:28 PM
  4. Urgent ! Need Advices On Windows Programming !
    By SonicWave in forum Windows Programming
    Replies: 6
    Last Post: 09-16-2001, 11:42 AM