内核对象与进程控制.pptx
文本预览下载声明
预备知识;名词解释;本章授课内容;Windows操作系统;Windows操作系统;Windows操作系统;Windows操作系统;Windows操作系统;内核对象;内核对象;内核对象;内核对象;void String::retain()
{
(*m_pCount)++;
}
void String::detain()
{
if( !(--(*m_pCount) ) )
{
delete []m_pData;
delete m_pCount;
}
}
int String::count() const
{
return *m_pCount;
}
String::~String()
{
detain();
};String::String( const char* aSrc ):m_pCount(new int(1))
{
m_pData = new char[strlen( aSrc )+ 1];
strcpy( m_pData, aSrc );
}
String::String( const String aRef )
:m_pCount(aRef.m_pCount),m_pData(aRef.m_pData)
{
retain();
}
String String::operator = ( const String aRef )
{
detain();
m_pCount = aRef.m_pCount;
m_pData = aRef.m_pData;
retain();
return *this;
};内核对象;内核对象;进程的创建;进程的创建;进程的创建;进程的创建;进程的创建;进程的创建;进程的创建;进程的创建;进程的创建;进程终止;进程终止;进程终止;进程终止;进程终止;进程控制;#include windows.h
#include tlhelp32.h // 声明快照函数的头文件
int main(int argc, char* argv[])
{
PROCESSENTRY32 pe32;
// 在使用这个结构之前,先设置它的大小
pe32.dwSize = sizeof(pe32);
// 给系统内的所有进程拍一个快照
HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE)
{
printf( CreateToolhelp32Snapshot调用失败! \n);
return -1;
}
// 遍历进程快照,轮流显示每个进程的信息
BOOL bMore = ::Process32First(hProcessSnap, pe32);
while(bMore)
{
printf( 进程名称:%s \n, pe32.szExeFile);
printf( 进程ID号:%u \n\n, pe32.th32ProcessID);
bMore = ::Process32Next(hProcessSnap, pe32);
}
// 不要忘记清除掉snapshot对象
::CloseHandle(hProcessSnap);
return 0;
};内容回顾
显示全部