티스토리 뷰
프로그램 카운터 과제는 1초마다 프로세스 수를 표시한다.
EnumProcess 함수를 통해 프로세스의 수를 구하면 된다.
print_less_ten은 내가 개인적으로 만든 함수이다.
날짜 표시할 때 10이하면 두자리수를 맞춰주지 못하기 때문에 그러한 경우 '0'을 출력하도록 하였다.
#pragma comment( lib, "Psapi.lib" ) #include <windows.h> #include <tchar.h> #include <psapi.h> #include <stdlib.h> #include <iostream> #include <time.h> using namespace std; void print_less_ten(int n){ // change print style for right format if(n<10){ cout << "0" ; } } int main( void ) { DWORD aProcesses[1024]; DWORD cbNeeded; DWORD cProcesses; time_t t = time(0); // set time type struct tm * now = localtime( & t ); // get time now while(1){ if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return 1; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); t = time(0); now = localtime( & t ); cout << (now->tm_year + 1900) << '_'; // print year print_less_ten(now->tm_mon + 1); cout << (now->tm_mon + 1) << "_" ; // print month print_less_ten(now->tm_mday); cout << now->tm_mday << " : "; // print day print_less_ten(now->tm_hour); cout << now->tm_hour << "_" ; // print hour print_less_ten(now->tm_min); cout << now->tm_min << "_"; // print minute print_less_ten((now->tm_sec)+1); cout << (now->tm_sec + 1); // print second cout << " : " << cProcesses << "\n"; // print processes count Sleep(1000); // number is in milliseconds 1Sec = 1000 MiliSeconds } return 0; }
' la fermata, 개발 > C, C++' 카테고리의 다른 글
[Code] multiplication table / 구구단 (0) | 2019.02.19 |
---|---|
[Code] CPU load (0) | 2019.02.19 |