You are on page 1of 1

OS LAB Process Management Ex. No.

– 4

#include "stdafx.h"
#include <Windows.h>
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])


{
STARTUPINFO si;

PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );

ZeroMemory( &pi, sizeof(pi) );

if(!CreateProcess(L"c:\\WINDOWS\\system32\\calc.exe",NULL,NULL,FALSE,0,NULL,NULL,NULL,&si,&pi ))
//OR
//LPCWSTR target = _T("c:\\WINDOWS\\system32\\calc.exe");
//if(!CreateProcess(target,NULL,NULL, FALSE, NULL,NULL, NULL, NULL, &si, &pi) )
{
cout<<"CreateProcess failed \n"<<GetLastError() ;

}
else
{
cout << "Waiting on process for 10 seconds.." << endl;
WaitForSingleObject(pi.hProcess, 10 * 1000);
// to close app
if ( PostThreadMessage(pi.dwThreadId, WM_QUIT, 0, 0) )
cout << "Request to terminate process has been sent! \n";

CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);

cout<<"Process information : \n";


cout<<" process id : "<< pi.dwProcessId<<"\n"<<"thread id : "<<pi.dwThreadId<<endl;

}
getchar();

return 0;
}

Asst. Lect. Amthal Khaleel Page 1 of 1

You might also like