MFC processes and threads

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.