惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - wolflion

《UNIX-Shell编程24学时教程》读书笔记Chap3,4 文件,目录操作 《UNIX-Shell编程24学时教程》读书笔记Chap1,2 Shell基础,脚本基础 《UNIX-Shell编程24学时教程》读书笔记chap7 变量 《软件调试的艺术》读书笔记 ubuntu环境准备 ftp的实现 icmp的程序(ping的实现) cp命令 who命令 苦逼IT才能看懂的笑话 debug和release版区别 i5处理器的台式机[百度知道] 关于轮胎尺寸问题 常见内核数据结构.doc windows 系统编程 Chap7 线程和调度 EVRYTHNG.H Windows系统编程 chap5 booklist 转 windows code
Windows系统编程chap6
wolflion · 2013-05-17 · via 博客园 - wolflion

Windows系统编程chap6   P134

进程管理

进程将其代码和数据存储在自己独立的虚拟地址空间里,以免受其他进程的影响。每个进程又包含一个或多个独立的线程。进程的线程可以创建新的线程以及新的独立进程,并管理对象间的通信和同步。

通过创建和管理进程,应用程序可以用多个并发任务来处理文件,执行计算或同其他网络系统进行通信。甚至可以使用多处理器来加速处理。

Windows进程和线程

从程序员角度,每个Windows进程包括如下资源组件:

一个或多个线程;

一个虚拟空间;

一个或多个代码段;

一个或多个包含全局变量的数据段;

环境字符串,

进程堆

进程的每个线程共享代码,全局变量,环境字符串和资源。每个线程都独立进行调度,并包含如下要素:

为过程调用,中断,异常处理器和自动存储建立的堆栈;

线程本地存储(TLS)—指针数组,

堆栈参数

上下文结构

《inside windows 2000》了解OS必读;

进程创建

.1 指定可执行的映像和命令行

。2 可继承句柄

进程句柄计数

              BOOL GetProcessHandleCount()

进程标识

     HANDLE GetCurrentProcess(VOID)

复制句柄

退出及终止进程

等待进程终止

环境块和字符串

范例:并发模式查找

/*Chap6. grepMP. Multiple process version of grep command.*/
#include "EvryThng.h"
int _tmain(DWORD argc, LPTSTR argv[])
/*Create a separate process to search each file on the command line.
Each process is given a temporary file, in the current directory, to receive the result.*/
{
HANDLE hTempFile;
//SA for inheritable handle.
SECURITY_ATTRIBUTES StdOutSA = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
TCHAR CommandLine[MAX_PATH + 100];
STARTUPINFO StartUpSearch, StartUp;
PROCESS_INFORMATION ProcessInfo;
DWORD iProc, ExCde;
HANDLE *hProc;/*Pointer to an array of proc handles.*/
typedef struct {TCHAR TempFile[MAX_PATH]} PROCFILE;
PROCFILE *ProcFile;/*Pointer to array of temp file names.*/
GetStartupInfo(&StartUpSearch);
GetStartupInfo(&StartUp);
ProcFile = malloc((argc - 2) * sizeof(PROCFILE));
hProc = malloc((argc - 2) * sizeof(HANDLE));
/*Create a separate "grep" process for each file.*/
for (iProc = 0; iProc < argc - 2; iProc++)
{
_stprintf(CommandLine, _T("%s%s %s"), _T("grep"), argv[1], argv[iProc + 2]);
GetTempFileName(_T("."), _T("gtm"), 0, ProcFile[iProc].TempFile);/*For search results.*/
/*This handle is inheritable*/
hTempFile = CreateFile(ProcFile[iProc].TempFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, &StdOutSA,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
StartUpSearch.dwFlags = STARTF_USESTDHANDLES;
StartUpSearch.hStdOutput = hTempFile;
StartUpSearch.hStdError = hTempFile;
StartUpSearch.hStdInput = GetStdHandle(STD_INPUT_HANDLE);

/*Create a process to execute the command line.*/
CreateProcess(NULL, CommandLine, NULL, NULL, TRUE, 0, NULL, NULL, &StartUpSearch, &ProcessInfo);
/*Close unwanted handles.*/
CloseHandle(hTempFile);
CloseHandle(ProcessInfo.hThread);
hProc[iProc] = ProcessInfo.hProcess;
}
/*Process are all running. Wait for them to complete.*/
for (iProc = 0; iProc < argc - 2; iProc += MAXIMUM_WAIT_OBJECTS)
{
//Allows a large # of processes
WaitForMultipleObjects(min(MAXIMUM_WAIT_OBJECTS, argc - 2 - iProc), &hProc[iProc], TRUE, INFINITE);
}
/*Result files sent to std output using "cat."*/
for (iProc = 0; iProc < argc - 2; iProc++)
{
if (GetExitCodeProcess(hProc[iProc], &ExCde) && ExCde == 0)
{
//Pattern was detected ---List results.
if (argc > 3)
{
_tprintf(_T("%s:\n"), argv[iProc + 2]);
}
fflush(stdout);//Multiple processes use stdout.
_stprintf(CommandLine, _T("%s%s"), _T("cat"), ProcFile[iProc].TempFile);
CreateProcess(NULL, CommandLine, NULL, NULL, TRUE, 0, NULL, NULL, &StartUp, &ProcessInfo);
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
}
CloseHandle(hProc[iProc]);
DeleteFile(ProcFile[iProc].TempFile);
}
free(ProcFile);
free(hProc);
return 0;
}

任务对象

Chap7 线程和调度     P161

7.1 线程概览

章线程进程的缺点:

7.2 线程基础

7.3 线程管理

createthread()

7.3.1 线程标识

      其他线程管理函数

//7-10章说明如何管理和同步进程内的线程

//6创建和管理进程

Chap11 进程间通信    P246

Chap12 windows套接字进行网络编程   P 269

Chap 13  windows服务    P296

13.1 编写Windows服务概览

13.2 main()服务

新的main()函数由SCM来调用,负责用SCM来注册服务,以及启动服务控制调度程序。

使用一个或多个逻辑服务的名称和入口点来调用函数StartServiceCtrlDispatcher

#include "EvryThng.h"

void WINAPI ServiceMain(DWORD argc, LPTSTR argv[]);

static LPTSTR ServiceMain = _T("SocketCommandLineService");

/*Main routine that starts the service control dispatcher.*/

VOID _tmain(int argc, LPTSTR argv[])

{

        SERVICE_TABLE_ENTRY DispatchTable[] =

        {

                { ServiceName, ServiceMain},

                { NULL, NULL}

        };

        if (!StartServiceCtrlDispatcher(DispatchTable))

        {

                ReportError(_T("Failed to start srvc ctrl dis."), 1, TRUE);

        }

        /*ServiceMain() will not run until started by the SCM.*/

        /*Return here only when all services have terminated. */

        return;

}

13.3 ServiceMain()函数