Skip to content
VUBuddy

CS609 Updated Handouts

System Programming PDF 6.5 MBUpdated 23 Oct 2026
Handout CS609 Updated Handouts PDF 6.5 MB
vubuddy.com
Type
Handout
Course
CS609 System Programming
Size
PDF 6.5 MB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 6.5 MB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

Preview text

Text from pages 1, 2, 3 of 141. Download the file for all 141 pages.

CS609 · SYSTEM PROGRAMMING · 93 T0 190 · Arranged By Amna · Topic 93: Process Identities

Process identity can be obtained from the PROCESS_INFORMATION structure. The CreateProcess() API returns the process information in its last parameter. This structure contains the child process handle and id as well as the primary thread handle and id. Closing the child process handle does not destroys the process. It only closes the access of the parent process to the child.

Let’s consider these pair of functions for this purpose:

HANDLE GetCurrentProcess (VOID)

DWORD GetCurrentProcessId(VOID)

GetCurrentProcess() is used to create a psuedohandle. It’s not inheritable and desired access attributes are undefined. The actual handle can be obtained using Process Id. The OpenProcess() function is used to obtain the process handle using the process ID obtained by GetCurrentProcessId() or otherwise.

HANDLE OpenProcess( DWORD dwDesiredAccess,

dwDesiredAccess provides the desired access attributes for the handle. Some of the commonly required values can be

SYCHRONIZE : Allows process synchronization using wait()

PROCESS_ALL_ACCESS : All access flags are set.

PROCESS_TERMINATE: It’s possible to terminate the process with TerminateProcess PROCESS_QUERY_INFORMATION: The handle can be used to query process information

bInheritHandle is used to specify whether the new process handle can be inherited.

The full pathname of the executable file used to run the process can be determined from

GetModuleFileName()

GetModuleFileNameEx()

Topic 94: Duplicating Handles

Parent and Child processes may require different access to an inheritable handle of resources. Parent Process may also require real handle rather than a pseudohandle. Parent process usually creates a duplicate handle to take care of this problem. Duplicate handles are created using

API DuplicateHandle()

BOOL DuplicateHandle( HANDLE hSourceProcessHandle,

HANDLE hSourceHandle,

HANDLE hTargetProcessHandle,

LPHANDLE lpTargetHandle,

DWORD dwDesiredAccess,

BOOL bInheritHandle,

DWORD dwOptions );

hSourceProcessHandle is the source process handle. lpTargetHandle receives a pointer to a copy of the original handle indicated by hSourceHandle. The parent process duplicating the handle must have PROCESS_DUP_HANDLE access. If the hSourceHandle does not exist in the source process then the function will fail. The target handle received will only be valid in the process whose handle is specified in hTargetProcessHandle.

Usually the handle is duplicated by the source or target process. In case it is duplicated by some other process than a mechanism is required to communicate with the target process DuplicateHandle() can be used to duplicate any sort of handle. dwOption can be combination of two flags.

DUPLICATE_CLOSE_SOURCE : causes the source handle to be closed

DUPLICATE_SAME_ACCESS: Uses the access rights of the source handle. dwDesiredAccess is ignored, Reference Count. Windows keep track of all the handles created for a resource. This count is not accessible to the application. A resource cannot be released unless the last reference to the resource has been closed. Inherited and duplicated handles reflect on reference count.

Topic 95: Exiting and Terminating a Process

A process can exit using the API ExitProcess(). The function does not return, in fact the process and all its associated threads terminate. Termination Handlers are ignored. However, a detach call is sent to DllMain().

VOID ExitProcess(UINT uExitCode) ;

Exit Code

The exit code of the process can be determined using the API GetExitCodeProcess()

BOOL GetExitCodeProcess( HANDLE hProcess, LPDWORD lpExitCode );

The process identified by hProcess must have PROCESS_QUERY_INFORMATION flag set.

lpExitCode points to the dword that will receive the exit code of the given process.

One possible value of Exit code can be STILL_ACTIVE

Terminate Process

One process can terminate another process using the function TerminateProcess()

BOOL TerminateProcess( HANDLE hProcess, UINT uExitCode );

hProcess is the handle to the process to be terminated

uExitCode is the code returned by the process on termination.

Exiting and Terminating Process

Process must be exited and terminated carefully. All the handles need to be closed before exiting the process. It’s not a good idea to use ExitProcess() within the program as it will not give it chance to release resources. Use is with Exception handling. TerminateProcess() does not all the process to execute SHE or DllMain().

All CS609 files →
CS609 System Programming All CS609 handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.