Скачиваний:
20
Добавлен:
01.05.2014
Размер:
3.3 Кб
Скачать
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <Tlhelp32.h>
#include <conio.h>

using namespace std;
void bubble(string etal[100],int item[100],int count);
void bubble1(DWORD etal[1000],int item[1000],int count);
void bubble(string etal[100],int item[100],int count)
{
register int a,b;
int t;string x;
 for(a=1;a<count;++a)
   for(b=count-1;b>=a;--b)
    {
     if(item[b-1]>item[b])
     {                     
     t=item[b-1];
     item[b-1]=item[b];
     item[b]=t;
          x=etal[b-1];
          etal[b-1]=etal[b];
          etal[b]=x;                                              
     }
    }                           
}
void bubble1(DWORD etal[1000],int item[1000],int count)
{
register int a,b;
int t;DWORD x;
 for(a=1;a<count;++a)
   for(b=count-1;b>=a;--b)
    {
     if(item[b-1]>item[b])
     {                     
     t=item[b-1];
     item[b-1]=item[b];
     item[b]=t;
          x=etal[b-1];
          etal[b-1]=etal[b];
          etal[b]=x;                                              
     }
    }                           
}
int main(int argc, char *argv[])
{
    cout<<"\t\tLaboratory working number 7"<<endl;
                    //*****Делаем снимок процессов системы******
    HANDLE Snapshot,Snapshot1;
    Snapshot=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS,0);
    if(Snapshot==INVALID_HANDLE_VALUE){cout<<"Error!"<<endl;}
         //*****Получение первого процесса в слепке,потом следующий*****
    PROCESSENTRY32 First;                
    BOOL Flag=1,Next;
    int i=0;
    int prioritet[100];
    string ProcessName[100];
    First.dwSize=sizeof(PROCESSENTRY32);
    Next = Process32First(Snapshot,&First);
    cout<<"\t\tList of process:"<<endl;
    while(Next){     
                 prioritet[i]=(int)First.pcPriClassBase;
                 ProcessName[i]=(string)First.szExeFile;               
                 First.dwSize = sizeof(PROCESSENTRY32);
				 Next = Process32Next(Snapshot, &First);
                 i++;    
                }
         bubble(ProcessName,prioritet,i);
         for(int j=0;j<i;j++)
         {
     cout<<"\t"<<ProcessName[j];
     cout <<"\tPrioritet - " <<prioritet[j]<< endl;       
         }        
        //*****Делаем снимок потоков системы*****           
    Snapshot1= CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
    if(Snapshot1==INVALID_HANDLE_VALUE){cout<<"Error!"<<endl;}
               //*****Получение первого потока в слепке,потом следующий
    THREADENTRY32 First1;
    int i1=0;
    int prioritet1[1000];
    DWORD ThreadName[1000];
    First1.dwSize = sizeof(THREADENTRY32);
    Next = Thread32First(Snapshot1, &First1);
    cout<<"\t\tList of threads:"<<endl; 
    while(Next){
                  prioritet1[i1]=(int)First1.tpBasePri;
                  ThreadName[i1]=First1.th32ThreadID;
                 First1.dwSize = sizeof(THREADENTRY32);
				 Next = Thread32Next(Snapshot1,&First1);
				 i1++;
                 }  
     bubble1(ThreadName,prioritet1,i1);
     for(int j1=0;j1<i1;j1++)
     {
     cout<<"\tID of thread - "<<ThreadName[j1];
     cout<<"\tPrioretet (base) - "<<prioritet1[j1]<<endl;         
     }            
   system("PAUSE");
   return EXIT_SUCCESS;
}

Соседние файлы в папке Лабораторная работа 7