Windows core programming Reading Notes-Process

Source: Internet
Author: User

Chapter 4 Process:

1. Generally, a process is defined as an instance of a running program, which consists of the following two parts.

A kernel object used by the operating system to manage processes. The kernel object is also the place where the system saves process statistics.

An address space that contains the code and data of all executable files or DLL modules.

2. Each process must have at least one thread to execute the Code contained in the process address space. If no thread needs to execute the Code contained in the process address space, the process will lose the reason for its continued existence. The system will automatically destroy the process and its address space.

3. During vs development, use the linker to switch/subsystem: console or/subsystem: Windows to set whether to load the application or window.

4. There are four entry-point functions for Windows applications (whether to load the application, whether to use Unicode, and four combinations of two-dimensional options ). They are:

_ Twinmain (winmain). The startup function for embedding executable files is winmaincrtstartup.

_ Twinmain (wwinmain). The startup function for embedding executable files is wwinmaincrtstartup.

_ Tmain (main). The start function for embedding executable files is maincrtstartup.

_ Tmain (wmain). The startup function for embedding executable files is wmaincrtstartup.

Select the corresponding entry function as the link based on the above linker switch.

5. the source code of the above-mentioned startup function is in the crtexe. c file. The main usage is summarized as follows:

Gets a pointer to the complete command line pointing to the new process.

Gets a pointer to the environment variable of the new process.

Initialize the combined variable of the C/C ++ Runtime Library. If stdlib. H is included, our code can access these variables.

Initializes the heap used by the memory allocation function (malloc, alloc) of the C-Runtime Library and other underlying I/O routines ).

Call constructors of all global and static C ++ class objects.

After completing the above initialization, call the entry point function of the application.

6. I mentioned the Memory Leak Detection Method and have reposted the article in this blog.

7. Get and use process instance handle: getmodulehandle, getmodulehandlerex, getmodulefilename

8. Get the process command line: getcommandline, commandlinetoargvw

9. process environment variables: getenvironmentstrings, freeenvironmentstrings, getenvironmentvariable, setenvironmentvariable

10. Function of process-related path: getcurrentdirectory, getfullpathname

11. Create a process function CreateProcess, the most important function in this chapter. Its operating mechanism:

A. the system creates a process kernel object;

B. The system creates a virtual address space for the process and loads the code and data of executable files to the virtual address space;

C. The system creates a thread kernel object for the main thread of the new process;

D. The main thread executes the startup routine during the C/C ++ runtime and the Application Execution portal;

E. If the new process and main thread are successfully created, true is returned.

See: http://social.msdn.microsoft.com/search/en-us/windows/desktop? Query = CreateProcess & refinement = 181

Parameter usage is the key of this chapter.

12. Terminate the process function exitprocess. It is an insecure function and should not be called in the program. In this process, you can use the constructor and destructor to print whether to call or not.

13. terminateprocess is a security function that can be used to terminate a process.

14. the child process has the ID of the parent process when it is created. However, if the parent process is terminated, this ID is meaningless. If no synchronization signal is sent, it indicates that the parent process has not ended, do not use this ID to do things.

15. When the Administrator runs with standard user permissions: these contents are newly added to Windows Vista and Windows 7 7. They are also relatively independent and important. A further summary is provided.

The book has come to the end, and it is known that this matter should be done.

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.