Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Detecting when a process is idle

Detecting when a process is idle

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialcareer
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Deem
    wrote on last edited by
    #1

    I am writing an application to do some batch processing. Basically it uses CreateProcess() to create a processes (with the desired command line arguments) over and over a number of times. Each run produces a text file which i will compile together. My problem however is that the process i am executing will perform its job and NOT close. If i call CreateProcess() while the application is still opened it ignores my arguments and does nothing, so i need to close between each execution. Can anybody offer any suggestions as to how to detect when the process has completed the work. I am confident that i can tell it to close, im just not sure how to determine when. The processing time is unpredictable. The cpu is used intensively during the operation. I attempted using the ForegroundIdleProc() hook function to flag me when the foreground thread went idle, however this does not seem to work (the function is hooked ok, as it is called when i close the app as well as scroll around in the app, it just doesnt call it when i want it to!). Any suggestions would be greatly appreciated. Alex Deem

    M 1 Reply Last reply
    0
    • A Alex Deem

      I am writing an application to do some batch processing. Basically it uses CreateProcess() to create a processes (with the desired command line arguments) over and over a number of times. Each run produces a text file which i will compile together. My problem however is that the process i am executing will perform its job and NOT close. If i call CreateProcess() while the application is still opened it ignores my arguments and does nothing, so i need to close between each execution. Can anybody offer any suggestions as to how to detect when the process has completed the work. I am confident that i can tell it to close, im just not sure how to determine when. The processing time is unpredictable. The cpu is used intensively during the operation. I attempted using the ForegroundIdleProc() hook function to flag me when the foreground thread went idle, however this does not seem to work (the function is hooked ok, as it is called when i close the app as well as scroll around in the app, it just doesnt call it when i want it to!). Any suggestions would be greatly appreciated. Alex Deem

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Call WaitForSingleObject() on the process handle:

      STARTUPINFO si = {sizeof(STARTUPINFO)};
      PROCESS_INFORMATION pi;

      if ( CreateProcess(..., &si, &pi) )
      {
      WaitForSingleObject ( pi.hProcess, INFINITE );
      CloseHandle ( pi.hProcess );
      CloseHandle ( pi.hThread );
      }

      Your thread will block in the Wait call until the child process exits. --Mike-- http://home.inreach.com/mdunn/ You are the weakest link, GOODBYE!

      A 1 Reply Last reply
      0
      • M Michael Dunn

        Call WaitForSingleObject() on the process handle:

        STARTUPINFO si = {sizeof(STARTUPINFO)};
        PROCESS_INFORMATION pi;

        if ( CreateProcess(..., &si, &pi) )
        {
        WaitForSingleObject ( pi.hProcess, INFINITE );
        CloseHandle ( pi.hProcess );
        CloseHandle ( pi.hThread );
        }

        Your thread will block in the Wait call until the child process exits. --Mike-- http://home.inreach.com/mdunn/ You are the weakest link, GOODBYE!

        A Offline
        A Offline
        Alex Deem
        wrote on last edited by
        #3

        I believe u misunderstood me. The child process does NOT exit. After doing the processing it sits there displaying the results in its UI. (The child app is a 3rd party app, so i have no control over this). I wish to determine how to detect when the app is sitting there idle, so i can then kill it. Alex Deem

        T 1 Reply Last reply
        0
        • A Alex Deem

          I believe u misunderstood me. The child process does NOT exit. After doing the processing it sits there displaying the results in its UI. (The child app is a 3rd party app, so i have no control over this). I wish to determine how to detect when the app is sitting there idle, so i can then kill it. Alex Deem

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          Use WaitForInputIdle. Tomasz Sowinski -- http://www.shooltz.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups