0% found this document useful (0 votes)
82 views

Os Lab Process Management Ex. No. - 4: To Understand How To Deal With Threads and Processes Using C++

This document provides information on creating threads and processes in C++. It explains the syntax for the CreateThread and CreateProcess functions. It then asks the reader to write a program that creates a process to launch the Windows calculator application, allows it to run for 10 seconds, and then terminates the process. Hints are provided to use the CreateProcess function to launch calc.exe, the WaitForSingleObject function to wait 10 seconds, and the CloseHandle function to terminate the process.

Uploaded by

xc33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Os Lab Process Management Ex. No. - 4: To Understand How To Deal With Threads and Processes Using C++

This document provides information on creating threads and processes in C++. It explains the syntax for the CreateThread and CreateProcess functions. It then asks the reader to write a program that creates a process to launch the Windows calculator application, allows it to run for 10 seconds, and then terminates the process. Hints are provided to use the CreateProcess function to launch calc.exe, the WaitForSingleObject function to wait 10 seconds, and the CloseHandle function to terminate the process.

Uploaded by

xc33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

OS LAB Process Management Ex. No.

– 4

Aim

To understand how to deal with threads and processes using C++.

Creating a new thread syntax

HANDLE WINAPI CreateThread(


_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ SIZE_T dwStackSize,
_In_ LPTHREAD_START_ROUTINE lpStartAddress,
_In_opt_ __drv_aliasesMem LPVOID lpParameter,
_In_ DWORD dwCreationFlags,
_Out_opt_ LPDWORD lpThreadId
);

Creating a new process syntax

BOOL WINAPI CreateProcessW(


_In_opt_ LPCWSTR lpApplicationName,
_Inout_opt_ LPWSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCWSTR lpCurrentDirectory,
_In_ LPSTARTUPINFOW lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);

Now, write a C++ program to create a process that starts a windows application such as the
calculator, allows user to use it for 10 seconds then terminates this application.

Hints

1. Use the specified application path, i.e. "c:\\WINDOWS\\system32\\calc.exe", as


lpApplicationName in the function CreateProcess.

2. Use the function:

DWORD WINAPI WaitForSingleObject( _In_ HANDLE hHandle, _In_ DWORD dwMilliseconds);


for setting the waiting time.

3. Use the function:


BOOL WINAPI CloseHandle(_In_ HANDLE hObject ); to terminate the process.

Asst. Lect. Amthal Khaleel Page 1 of 1

You might also like