013 Windows processes and threads

Source: Internet
Author: User

Windows Processes and Threads

The composition of the process
0 The process is "lazy", and anything that the process is going to do must be run by the thread, and the threads execute the code contained in the process address space

? The process itself cannot run anything

? The process delimits a region, there are some code, the code is static


0 A process can have multiple threads, all of which can "simultaneously" run code in the address bow of a process, each with his own set of CPU registers and his own stack.

? A process can have a minimum of one thread

? If no thread inside a process is destroyed


0 Each process must have one thread, and a thread is created automatically when the system creates a process. This thread is what we call the main threads. If no thread is executing the code in the process address space, the process loses its meaning, and the process is automatically destroyed and its address space

? Code for thread execution CPU

? Windows is an operating system that supports multi-process technology


0 The operating system allocates CPU time slices for each thread in a poll, creating a "parallel" illusion.

0 if the computer has more than one CPU, the operating system will have more complex ways to allocate CPU time to the thread.



Kernel Objects
0 operating system for managing processes


address Space
0 contains code and data for executables and DLL modules


Application Type

Console User interface
0 Console programs are text-based they generally do not create windows or process messages, and do not require a GUI

? Programs that interact with text are called Cui

? Text-based operations called Cui

? Not that the CMD execution program is called Cui.

// The Win32API We're learning now are all in C-function mode. //

Graphical user interface
0 GUI Program a graphical front-end, which can create windows, can have menus, can interact with users through dialog boxes, and can use all the tiles "windowing" things Windows almost all attachment applications are GUI programs

Difference

In VS, the linker switch bit of the CUI program/subsystem:console,gui the linker switch bit of the program/SUBSYSTEM: WINDOWS. When loaded, gets this value, and if it is a text console window, the operating system uses a command prompt to start the program, otherwise it just loads this, and the application manages its own window
The entry function is different.

int WINAPI _tWinMain (    hinstance hinstanceexe,    hinstance hpreinstancec,    ptstr pszcmdline,     int ncmdshow);
1 int _tmain (2     int argc, 3     TCHAR *argv[],4     TCHAR *envp[]5     );

0 startup function is different, the starting function of the GUI WinMainCRTStartup or wwinmaincrtatup,cui start function is mainCRTStartup or Wmaincstartup

? Command prompt is a software that completely independent software

? The program we develop is another software, if the command line is set inside, or the console, user interface properties

1#include <Window.h>2#include <tchar.h>3 //Main CUI -4 //winmin GUI-New or attach a console program5 6 //program7 //cannot parse external symbol _main, which is referenced in function "int __cdecl invoke main (void)" ([email protected] @YAHXZ)8 //Find the main function9 //unresolved external symbol [email protected], which is referenced in function "int __cdecl invoke_main (void)" ([email protected] @YAHXZ)Ten //Find WinMain Function One //CUI A intMain () - { -     return 0; the } - //linker switch bits for GUI programs - intWINAPI _tWinMain ( - _in_ hinstance hinstance, //process handle  + _in_ hinstance hprevinstance, //Handle of previous process try not to use or not use  - _in LPTSTR lpCmdLine, //command line  +_in_intncmdshow) //Display the way sw_show sw_hide  A { at     return 0 -}

1#include <tchar.h>2#include <windows.h>3 4#include <stdio.h>5 6 intMain ()7 {8HINSTANCE hinstance = GetModuleHandle (NULL);//Get Window Handle9                                                             //Program Matrix 0x400000Tenprintf"0x%x\r\n", hinstance); One      Atchar*ConstStrcommline =GetCommandLine (); -             //LPTSTR WINAPI getcommandline (void); -_tprintf (TEXT ("%s\r\n"), strcommline); the     intnnumargv; -lpwstr* ppargv = COMMANDLINETOARGVW (Strcommline, &nnumargv); -     if(PPARGV! =NULL) -     { +          for(intNIndex =0; NIndex < NNUMARGV; ++NIndex) -         { +_tprintf (TEXT ("%s\r\n"), Ppargv[nindex]); A         } at     } -      -  -System"Pause"); -     return 0; -}

1 // Environment Variables 2 lptch strpath = getenvironmentstring (); 3 _tprintf (TEXT ("%s \ r \ n"), strpath); 4 // freeenvironmentstrings ();

013 Windows processes and threads

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.