Running simultaneous processes

This is a discussion on Running simultaneous processes within the Windows Programming forums, part of the Platform Specific Boards category; I am in the process of writing a service that is similar to UNIX cron. I need to be able ...

  1. #1
    Registered User
    Join Date
    May 2003

    Running simultaneous processes

    I am in the process of writing a service that is similar to UNIX cron.
    I need to be able to run multiple processes simultaneously. The code below always waits for one process to finish before continuing. Can someone point me in the right direction to allow the program to continue without waiting. Basically, allow processes to run in the background.


    while (ServiceStatus.dwCurrentState ==
    for(i=0; i<lines; i++)
    if(check_time(i) == 1)


    ServiceStatus.dwCurrentState =
    ServiceStatus.dwWin32ExitCode = -1;
    LogMsg("MyCron stopped.");

    int execute_process(int i)
    char command[64];



    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    // Start the child process.
    if( !CreateProcess( NULL, command, NULL,
    NULL, FALSE, 0, NULL, NULL, &si, &pi )
    _ErrorExit( "CreateProcess failed." );

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );

    return 0;

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    >>WaitForSingleObject( pi.hProcess, INFINITE );

    Without testing, I would say this line is the's making the program wait for the child program to end

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    On an unrelated-to-your-question note, marksw, when you post your source make sure it's within a code block (by starting it with [code] and ending it with [/code]) so that it retains your formatting, thus making it easy on everyone's eyes.

  4. #4
    Fordy is right, if you simply remove that wait line, it will work just fine. It seems to be OK to close the handles before the thread & process terminate; it obviously won't terminate the process or thread and I don't think there are any memory leaks.

  5. #5
    Registered User
    Join Date
    May 2003

    Thumbs up

    Thanks for the help.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    No leaks.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Running processes
    By pfs in forum Linux Programming
    Replies: 6
    Last Post: 01-01-2009, 07:23 PM
  2. Simultaneous processes
    By Lateralus in forum C Programming
    Replies: 5
    Last Post: 06-30-2005, 08:58 PM
  3. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 11:59 PM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  5. RE: Find out running processes from command prompt
    By sampatel in forum A Brief History of
    Replies: 2
    Last Post: 10-18-2001, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21