资源简介
数据结构课程设计中的统计系统进程源程序
c++ 可运行
代码片段和文件信息
#include
#include
#include
#include
#include
#include“string.h“
#include“Psapi.h“
#include“time.h“
#pragma comment(lib“Psapi.lib“)
using namespace std;
struct linklist
{
char name[20];
long memory;
time_t start;
int miniute;
int second;
linklist *prior;
linklist *next;
bool Flag;
}*head1*head2*p1*p2*Ptime;
int PrintMemoryInfo(DWORD processID)//获取内存
{
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc;
hProcess=OpenProcess(PROCESS_QUERY_INFORMATION |PROCESS_VM_READFALSE processID);
if(hProcess==NULL)
return 0;
if(GetProcessMemoryInfo(hProcess&pmcsizeof(pmc)))
{
CloseHandle(hProcess);
return pmc.PeakWorkingSetSize;
}
}
int main()
{
int minitue1=0minitue2=0second1=0;
long cmemory; //当前进程所占内存大小
char cname[20]; //当前进程字
bool Flag;
int yearmondaysecond;
long t;
head1=new linklist;
head2=new linklist;
head1->next=head1;
head2->next=head2;
head1->prior=head1;
head1->Flag=0;
PROCESSENTRY32 temp; //存放进程信息的结构体
temp.dwSize=sizeof(temp);
HANDLE hProcessSnapshot=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS0);
if(INVALID_HANDLE_VALUE==hProcessSnapshot)
{
printf(“未获得进程!\n“);
return 0;
}
BOOL bMore=::Process32First(hProcessSnapshot&temp);
linklist *p*pb*pn; //pb指向p的前面,pn指向p的后面
time_t startendprocess;
process=start=time(NULL);
time_t ctime=time(0);
tm tim=*localtime(&ctime);
t=time(0);
year=tim.tm_year;
mon=tim.tm_mon;
day=tim.tm_mday;
while(1)
{
if(head1->Flag==0)
head1->Flag=1;
else
head1->Flag=0;
Flag=head1->Flag; //用以查看进程是否结束
printf(“正在运行的程序名 使用内存 持续时间 “);
printf(“已经结束的程序名 持续时间\n“);
while(bMore)
{
pn=NULL;
strcpy(cnametemp.szExeFile);
cmemory=PrintMemoryInfo(temp.th32ProcessID);
p=head1->next;
while(p!=head1&&strcmp(cnamep->name)!=0)
{
if(cmemory>=p->memory&&pb==NULL)
pn=p;
p=p->next;
}
if(strcmp(cnamep->name)==0)
{
end=time(NULL);
p->start=difftime(endp->start);
if(p->second>=60)
{
p->miniute++;
p->second=p->second%60;
}
else
p->second+=p->start;
p->start=time(NULL);
p->memory=cmemory;
p->Flag=Flag;
if(cmemory>p->prior->memory&&p->prior!=head1||cmemorynext->memory&&p->next!=head1)
{
pn=p->prior;
pb=p->next;
pn->next=pb;
pb->prior=pn;
pn=p;
if(cmemorynext->memory)
{
p=p->next;
while(p!=head1&&cmemorymemory)
p=p->next;
}
else
while(cmemory>p->prior->memory&&p->prior!=head1)
p=p->prior;//往前找比自己小的
// 插入位置已找到,插入
pb=p->prior ;
pb->next=pn;
pn->prior=pb;
pn->next=p;
p->prior=pn;
}
}
else
if(cmemory!=0)
{
{
if(p==head
- 上一篇:旋转的风车,使用MFC编写
- 下一篇:人机对战智能五子棋 C语言版
评论
共有 条评论