Win32Process and thread concepts
A process is an executable program consisting of private virtual address space, code, data, and other operating system resources (such as files, pipelines, and synchronization objects created by the process. An application can have one or more processes. A process can have one or more threads, one of which is the main thread.
Threads are allocated by time-based scheduling in the operating system.CPUThe basic entity of time. A thread can execute any part of the code of the program, even if the code is concurrently executed by another thread; all threads of a process share their virtual address space, global variables, and operating system resources.
The thread concept is introduced because it is more efficient to schedule objects with threads rather than processes:
The code to be executed by the thread must be loaded when a new process is created, and the code to be executed by the thread has been mapped to the address space of the process. Therefore, the speed of creating and executing the thread is faster than that of the process.
All threads of a process share the address space and global variables of the process, so communication between threads is simplified.
Win32Process Introduction
BecauseMFCNo class processing process is provided.Win32 APIFunction.
Process Creation
CallCreateProcessFunction to create a new process and run the specified program.CreateProcessThe prototype is as follows:
BOOL CreateProcess (
Lptstr lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
Maid directory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
Where:
LpApplicationNamePoint to a string containing the name of the module to be run.
LpCommandLinePoint to a command line string.
LpProcessAttributesDescribes the security attributes of a process,NT.
LpThreadAttributesDescribes the security attributes of the initial process thread (main thread,NT.
BInHeritHandlesIndicates whether a child process (the created process) can inherit the handle of the parent process. The handhandles that can be inherited include thread handles, famous or unknown pipelines, mutex objects, events, semaphores, image files, common files, and communication ports. Some handles cannot be inherited, such as memory handle,DLLInstance handle,GDIHandle,URERHandle.
The handle inherited by a sub-process is transmitted by the parent process through the command line or between processes (IPC.
DwCreationFlagsIndicates the priority category and process type of the created process. Create a process Type Sub-Console