nishzone
asked on
waitformultipleobjects function
hey,
i think i'm close to getting my program to work but i have a problem. I'm not wat to put in the second parameter of waitForMultipleObjects. Can somebody plz tell me.
Here is the code:
#include <iostream.h>
#include <windows.h>
#include <stdio.h>
int main()
{
PROCESS_INFORMATION pi[5];
int i;
for (i=5; i>0; i--)
{
STARTUPINFO si;
DWORD dwCode = 0;
ZeroMemory ( &si, sizeof ( STARTUPINFO));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
if(CreateProcess ( NULL,
"notepad.exe",
NULL,
NULL,
0,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi[i]
))
{
cout<<"The ID of notepad is "<<pi[i].dwProcessId <<endl;
}
else
{
cout<< "Error creating process:"<< GetLastError()<<endl;
}
}
for (i=5; i>0; i--)
{
while(WaitForMultipleObjec ts(5, pi.hProcess,TRUE, 1000) == WAIT_TIMEOUT)
{
cout<<i;
}
cout<<endl;
}
for (i=1, i<6, i++)
{
CloseHandle(pi[i].hThread) ;
CloseHandle(pi[i].hProcess );
}
}
i think i'm close to getting my program to work but i have a problem. I'm not wat to put in the second parameter of waitForMultipleObjects. Can somebody plz tell me.
Here is the code:
#include <iostream.h>
#include <windows.h>
#include <stdio.h>
int main()
{
PROCESS_INFORMATION pi[5];
int i;
for (i=5; i>0; i--)
{
STARTUPINFO si;
DWORD dwCode = 0;
ZeroMemory ( &si, sizeof ( STARTUPINFO));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
if(CreateProcess ( NULL,
"notepad.exe",
NULL,
NULL,
0,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi[i]
))
{
cout<<"The ID of notepad is "<<pi[i].dwProcessId <<endl;
}
else
{
cout<< "Error creating process:"<< GetLastError()<<endl;
}
}
for (i=5; i>0; i--)
{
while(WaitForMultipleObjec
{
cout<<i;
}
cout<<endl;
}
for (i=1, i<6, i++)
{
CloseHandle(pi[i].hThread)
CloseHandle(pi[i].hProcess
}
}
BOOL ExecuteAndWaitForCompletio n ( LPCTSTR pszCmd)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof (si));
ZeroMemory (&pi, sizeof (pi));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
DWORD bRes = CreateProcess ( NULL, (LPTSTR)pszCmd, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
GetEnvironmentStrings (), NULL, &si, &pi);
WaitForSingleObject ( pi.hProcess, INFINITE);
CloseHandle( pi.hProcess);
CloseHandle( pi.hThread);
return ( bRes);
}
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof (si));
ZeroMemory (&pi, sizeof (pi));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
DWORD bRes = CreateProcess ( NULL, (LPTSTR)pszCmd, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
GetEnvironmentStrings (), NULL, &si, &pi);
WaitForSingleObject ( pi.hProcess, INFINITE);
CloseHandle( pi.hProcess);
CloseHandle( pi.hThread);
return ( bRes);
}
ASKER
this is when u create only one process. i have to monitor 5 processes.
Deja vu ...
"how do i write a Win32 Console application that starts five threads, passing each a parameter which is the number of milliseconds that this thread is to simulate execution."
https://www.experts-exchange.com/questions/20715123/How-do-i-create-and-monitor-threads-in-c-Qn2.html
Follow the link, and maybe that is exactly what you are looking for. (Inclusive, it seems to be the same homework, are you friends?)
"how do i write a Win32 Console application that starts five threads, passing each a parameter which is the number of milliseconds that this thread is to simulate execution."
https://www.experts-exchange.com/questions/20715123/How-do-i-create-and-monitor-threads-in-c-Qn2.html
Follow the link, and maybe that is exactly what you are looking for. (Inclusive, it seems to be the same homework, are you friends?)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.axter.com/faq/topic.asp?TOPIC_ID=5&FORUM_ID=4&CAT_ID=9
http://www.axter.com/faq/topic.asp?TOPIC_ID=6&FORUM_ID=4&CAT_ID=9