ReactOS  0.4.14-dev-49-gfb4591c
ctm.c
Go to the documentation of this file.
1 /* Console Task Manager
2 
3  ctm.c - main program file
4 
5  Written by: Aleksey Bragin (aleksey@reactos.org)
6 
7  Most of the code dealing with getting system parameters is taken from
8  ReactOS Task Manager written by Brian Palmer (brianp@reactos.org)
9 
10  Localization features added by Hervé Poussineau (hpoussin@reactos.org)
11 
12  History:
13  24 October 2004 - added localization features
14  09 April 2003 - v0.1, fixed bugs, added features, ported to mingw
15  20 March 2003 - v0.03, works good under ReactOS, and allows process
16  killing
17  18 March 2003 - Initial version 0.01, doesn't work under RectOS
18 
19  This program is free software; you can redistribute it and/or modify
20  it under the terms of the GNU General Public License as published by
21  the Free Software Foundation; either version 2 of the License, or
22  (at your option) any later version.
23 
24  This program is distributed in the hope that it will be useful,
25  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  GNU General Public License for more details.
28 
29  You should have received a copy of the GNU General Public License
30  along with this program; if not, write to the Free Software
31  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
32 
33 
34 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows //headers
35 #define WIN32_NO_STATUS
36 #include <windows.h>
37 
38 #include <stdlib.h>
39 #include <malloc.h>
40 #include <memory.h>
41 #include <tchar.h>
42 #include <process.h>
43 #include <stdio.h>
44 
45 #define NTOS_MODE_USER
46 #include <ndk/ntndk.h>
47 
48 #include <epsapi/epsapi.h>
49 
50 #include "ctm.h"
51 #include "resource.h"
52 
53 #define TIMES
54 
58 
61 
70 TCHAR lpHeader[80];
73 
76 
77 int ProcPerScreen = 17; // 17 processess are displayed on one page
78 int ScreenLines=25;
81 
82 double dbIdleTime;
83 double dbKernelTime;
84 double dbSystemTime;
88 
89 PPERFDATA pPerfDataOld = NULL; // Older perf data (saved to establish delta values)
90 PPERFDATA pPerfData = NULL; // Most recent copy of perf data
91 
92 int selection=0;
93 int scrolled=0; // offset from which process start showing
94 int first = 0; // first time in DisplayScreen
96 
98 #define NEW_CONSOLE
99 
100 // Functions that are needed by epsapi
101 void *PsaiMalloc(SIZE_T size) { return malloc(size); }
102 void *PsaiRealloc(void *ptr, SIZE_T size) { return realloc(ptr, size); }
103 void PsaiFree(void *ptr) { free(ptr); }
104 
105 // Prototypes
106 unsigned int GetKeyPressed();
107 
109 {
110 #ifdef NEW_CONSOLE
114 
115  if (SetConsoleActiveScreenBuffer(console) == FALSE)
116  {
119  }
120  else
121  {
122  hStdin = GetStdHandle(STD_INPUT_HANDLE);//console;
123  hStdout = console;
124  }
125 #else
128 #endif
129 }
130 
132 {
135 
136 #ifdef NEW_CONSOLE
138 #endif
139 }
140 
142 {
143  COORD pos;
144  COORD size;
145  TCHAR lpStr[80];
146  DWORD numChars;
147  int lines;
148  int idx;
151  ScreenLines=size.Y;
153  if (first == 0)
154  {
155  // Header
156  pos.X = 1; pos.Y = 1;
158 
159  pos.X = 1; pos.Y = 2;
161 
162  pos.X = 1; pos.Y = 3;
164 
165  pos.X = 1; pos.Y = 4;
166  if (scrolled)
168  else
170 
171  // Footer
172  pos.X = 1; pos.Y = ScreenLines-2;
175  else
177 
178  // Menu
179  pos.X = 1; pos.Y = ScreenLines-1;
182 
183  first = 1;
184  }
185 
186  // Processess
188  if (lines > ProcPerScreen)
190  for (idx=0; idx<ProcPerScreen; idx++)
191  {
192  int i;
193  SIZE_T len;
194  TCHAR lpNumber[5];
195  TCHAR lpPid[8];
196  TCHAR lpCpu[6];
197  TCHAR lpMemUsg[12];
198  TCHAR lpPageFaults[15];
199  WORD wColor;
200 
201  for (i = 0; i < 80; i++)
202  lpStr[i] = _T(' ');
203 
204  // data
205  if (idx < lines && scrolled + idx < ProcessCount)
206  {
207 
208  // number
209  _stprintf(lpNumber, _T("%3d"), idx+scrolled);
210  _tcsncpy(&lpStr[2], lpNumber, 3);
211 
212  // image name
213 #ifdef _UNICODE
215 #else
217  imgName, MAX_PATH, NULL, NULL);
218  len = strlen(imgName);
219 #endif
220  if (len > columnRightPositions[1])
221  {
223  }
224 #ifdef _UNICODE
226 #else
227  strncpy(&lpStr[columnRightPositions[0]+3], imgName, len);
228 #endif
229 
230  // PID
231  _stprintf(lpPid, _T("%6ld"), pPerfData[scrolled+idx].ProcessId);
232  _tcsncpy(&lpStr[columnRightPositions[2] - 6], lpPid, 6);
233 
234 #ifdef TIMES
235  // CPU
236  _stprintf(lpCpu, _T("%3d%%"), pPerfData[scrolled+idx].CPUUsage);
237  _tcsncpy(&lpStr[columnRightPositions[3] - 4], lpCpu, 4);
238 #endif
239 
240  // Mem usage
241  _stprintf(lpMemUsg, _T("%6ld %s"), pPerfData[scrolled+idx].WorkingSetSizeBytes / 1024, lpMemUnit);
242  _tcsncpy(&lpStr[columnRightPositions[4] - 9], lpMemUsg, 9);
243 
244  // Page Fault
245  _stprintf(lpPageFaults, _T("%12ld"), pPerfData[scrolled+idx].PageFaultCount);
246  _tcsncpy(&lpStr[columnRightPositions[5] - 12], lpPageFaults, 12);
247  }
248 
249  // columns
250  lpStr[0] = _T(' ');
251  lpStr[1] = _T('|');
252  for (i = 0; i < 6; i++)
253  lpStr[columnRightPositions[i] + 1] = _T('|');
254  pos.X = 0; pos.Y = 5+idx;
255  WriteConsoleOutputCharacter(hStdout, lpStr, 80, pos, &numChars);
256 
257  // Attributes now...
258  pos.X = columnRightPositions[0] + 1; pos.Y = 5+idx;
259  if (selection == idx)
260  {
265  }
266  else
267  {
272  }
273 
275  hStdout, // screen buffer handle
276  wColor, // color to fill with
277  columnRightPositions[1] - 4, // number of cells to fill
278  pos, // first cell to write to
279  &numChars); // actual number written
280  }
281 
282  return;
283 }
284 
285 // returns TRUE if exiting
286 int ProcessKeys(int numEvents)
287 {
288  DWORD numChars;
289  TCHAR key;
290  if ((ProcessCount-scrolled < 17) && (ProcessCount > 17))
291  scrolled = ProcessCount-17;
292 
293  key = GetKeyPressed(numEvents);
294  if (key == KEY_QUIT)
295  return TRUE;
296  else if (key == KEY_KILL)
297  {
298  // user wants to kill some process, get his acknowledgement
299  DWORD pId;
300  COORD pos;
301  TCHAR lpStr[100];
302 
303  pos.X = 1; pos.Y =ScreenLines-1;
304  if (LoadString(hInst, IDS_KILL_PROCESS, lpStr, 100))
305  WriteConsoleOutputCharacter(hStdout, lpStr, _tcslen(lpStr), pos, &numChars);
306 
307  do {
309  key = GetKeyPressed(pId);
310  } while (key != KEY_YES && key != KEY_NO);
311 
312  if (key == KEY_YES)
313  {
317 
318  if (hProcess)
319  {
320  if (!TerminateProcess(hProcess, 0))
321  {
322  if (LoadString(hInst, IDS_KILL_PROCESS_ERR1, lpStr, 80))
323  {
325  WriteConsoleOutputCharacter(hStdout, lpStr, _tcslen(lpStr), pos, &numChars);
326  }
327  Sleep(1000);
328  }
329 
331  }
332  else
333  {
334  if (LoadString(hInst, IDS_KILL_PROCESS_ERR2, lpStr, 80))
335  {
337  _stprintf(lpStr, lpStr, pId);
338  WriteConsoleOutputCharacter(hStdout, lpStr, _tcslen(lpStr), pos, &numChars);
339  }
340  Sleep(1000);
341  }
342  }
343 
344  first = 0;
345  }
346  else if (key == VK_UP)
347  {
348  if (selection > 0)
349  selection--;
350  else if ((selection == 0) && (scrolled > 0))
351  scrolled--;
352  }
353  else if (key == VK_DOWN)
354  {
355  if ((selection < ProcPerScreen-1) && (selection < ProcessCount-1))
356  selection++;
357  else if ((selection == ProcPerScreen-1) && (selection+scrolled < ProcessCount-1))
358  scrolled++;
359  }
360  else if (key == VK_PRIOR)
361  {
362  if (scrolled>ProcPerScreen-1)
364  else
365  {
366  scrolled=0; //First
367  selection=0;
368  }
369  //selection=0;
370  }
371  else if (key == VK_NEXT)
372  {
375  {
378  }
379 
380  //selection=ProcPerScreen-1;
381  if (ProcessCount<=ProcPerScreen) //If there are less process than fits on the screen
382  {
383  scrolled=0;
385  }
386  }
387  else if (key == VK_HOME)
388  {
389  selection=0;
390  scrolled=0;
391  }
392  else if (key == VK_END)
393  {
396  if (ProcessCount<=ProcPerScreen) //If there are less process than fits on the screen
397  {
398  scrolled=0;
400  }
401  }
402  return FALSE;
403 }
404 
405 void PerfInit()
406 {
408 }
409 
411 {
412  LONG status;
413  ULONG ulSize;
414  LPBYTE pBuffer;
415  ULONG Idx, Idx2;
417  PPERFDATA pPDOld;
418 #ifdef EXTRA_INFO
420  HANDLE hProcessToken;
421  TCHAR szTemp[MAX_PATH];
422  DWORD dwSize;
423 #endif
424 #ifdef TIMES
425  LARGE_INTEGER liCurrentKernelTime;
426  LARGE_INTEGER liCurrentIdleTime;
427  LARGE_INTEGER liCurrentTime;
428 #endif
429  PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
430  SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
431 
432 #ifdef TIMES
433  // Get new system time
434  status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
435  if (status != NO_ERROR)
436  return;
437 #endif
438  // Get processor information
441 
442 
443  // Get process information
445 
446 #ifdef TIMES
447  liCurrentKernelTime.QuadPart = 0;
448  liCurrentIdleTime.QuadPart = 0;
449  for (Idx=0; Idx<SystemBasicInfo.NumberOfProcessors; Idx++) {
450  liCurrentKernelTime.QuadPart += SysProcessorTimeInfo[Idx].KernelTime.QuadPart;
451  liCurrentKernelTime.QuadPart += SysProcessorTimeInfo[Idx].DpcTime.QuadPart;
452  liCurrentKernelTime.QuadPart += SysProcessorTimeInfo[Idx].InterruptTime.QuadPart;
453  liCurrentIdleTime.QuadPart += SysProcessorTimeInfo[Idx].IdleTime.QuadPart;
454  }
455 
456  // If it's a first call - skip idle time calcs
457  if (liOldIdleTime.QuadPart != 0) {
458  // CurrentValue = NewValue - OldValue
459  liCurrentTime.QuadPart = liCurrentIdleTime.QuadPart - liOldIdleTime.QuadPart;
460  dbIdleTime = Li2Double(liCurrentTime);
461  liCurrentTime.QuadPart = liCurrentKernelTime.QuadPart - liOldKernelTime.QuadPart;
462  dbKernelTime = Li2Double(liCurrentTime);
463  liCurrentTime.QuadPart = SysTimeInfo.CurrentTime.QuadPart - liOldSystemTime.QuadPart;
464  dbSystemTime = Li2Double(liCurrentTime);
465 
466  // CurrentCpuIdle = IdleTime / SystemTime
469 
470  // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
471  dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors;// + 0.5;
472  dbKernelTime = 100.0 - dbKernelTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors;// + 0.5;
473  }
474 
475  // Store new CPU's idle and system time
476  liOldIdleTime = liCurrentIdleTime;
477  liOldSystemTime = SysTimeInfo.CurrentTime;
478  liOldKernelTime = liCurrentKernelTime;
479 #endif
480 
481  // Determine the process count
482  // We loop through the data we got from PsaCaptureProcessesAndThreads
483  // and count how many structures there are (until PsaWalkNextProcess
484  // returns NULL)
486  ProcessCount = 0;
488  while (pSPI) {
489  ProcessCount++;
490  pSPI = PsaWalkNextProcess(pSPI);
491  }
492 
493  // Now alloc a new PERFDATA array and fill in the data
494  if (pPerfDataOld) {
496  }
500  for (Idx=0; Idx<ProcessCount; Idx++) {
501  // Get the old perf data for this process (if any)
502  // so that we can establish delta values
503  pPDOld = NULL;
504  for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
505  if (pPerfDataOld[Idx2].ProcessId == HandleToUlong(pSPI->UniqueProcessId) &&
506  /* check also for the creation time, a new process may have an id of an old one */
508  pPDOld = &pPerfDataOld[Idx2];
509  break;
510  }
511  }
512 
513  // Clear out process perf data structure
514  memset(&pPerfData[Idx], 0, sizeof(PERFDATA));
515 
516  if (pSPI->ImageName.Buffer) {
517  wcsncpy(pPerfData[Idx].ImageName, pSPI->ImageName.Buffer, pSPI->ImageName.Length / sizeof(WCHAR));
518  pPerfData[Idx].ImageName[pSPI->ImageName.Length / sizeof(WCHAR)] = 0;
519  }
520  else
521  {
522 #ifdef _UNICODE
524 #else
526 #endif
527  }
528 
530  pPerfData[Idx].CreateTime = pSPI->CreateTime;
531 
532  if (pPDOld) {
533 #ifdef TIMES
534  double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
535  double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
536  double CpuTime = (CurTime - OldTime) / dbSystemTime;
537  CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; // + 0.5;
538 
539  pPerfData[Idx].CPUUsage = (ULONG)CpuTime;
540 #else
541  pPerfData[Idx].CPUUsage = 0;
542 #endif
543  }
544 
548  if (pPDOld)
550  else
553  if (pPDOld)
555  else
560  pPerfData[Idx].BasePriority = pSPI->BasePriority;
561  pPerfData[Idx].HandleCount = pSPI->HandleCount;
563  //pPerfData[Idx].SessionId = pSPI->SessionId;
564 
565 #ifdef EXTRA_INFO
567  if (hProcess) {
569  ImpersonateLoggedOnUser(hProcessToken);
570  memset(szTemp, 0, sizeof(TCHAR[MAX_PATH]));
571  dwSize = MAX_PATH;
572  GetUserName(szTemp, &dwSize);
573 #ifndef UNICODE
574  MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTemp, -1, pPerfData[Idx].UserName, MAX_PATH);
575 #endif
576  RevertToSelf();
577  CloseHandle(hProcessToken);
578  }
580  }
581 #endif
582 #ifdef TIMES
585 #endif
586  pSPI = PsaWalkNextProcess(pSPI);
587  }
589 
590  free(SysProcessorTimeInfo);
592  first = 0;
593 }
594 
595 // Code partly taken from slw32tty.c from mc/slang
596 unsigned int GetKeyPressed(int events)
597 {
598  DWORD bytesRead;
600  int i;
601 
602 
603  for (i=0; i<events; i++)
604  {
605  if (!ReadConsoleInput(hStdin, &record, 1, &bytesRead)) {
606  return 0;
607  }
608 
609  if (record.EventType == KEY_EVENT && record.Event.KeyEvent.bKeyDown)
610  return record.Event.KeyEvent.wVirtualKeyCode;//.uChar.AsciiChar;
611  }
612 
613  return 0;
614 }
615 
616 
617 int _tmain(int argc, char **argv)
618 {
619  int i;
620  TCHAR lpStr[80];
621 
622  for (i = 0; i < 80; i++)
623  lpEmpty[i] = lpHeader[i] = _T(' ');
624  lpEmpty[79] = _T('\0');
625 
626  /* Initialize global variables */
627  hInst = 0 /* FIXME: which value? [used with LoadString(hInst, ..., ..., ...)] */;
628 
629  if (LoadString(hInst, IDS_COLUMN_NUMBER, lpStr, 80))
630  {
631  columnRightPositions[0] = _tcslen(lpStr) + 3;
632  _tcsncpy(&lpHeader[2], lpStr, _tcslen(lpStr));
633  }
634  if (LoadString(hInst, IDS_COLUMN_IMAGENAME, lpStr, 80))
635  {
637  _tcsncpy(&lpHeader[columnRightPositions[0] + 2], lpStr, _tcslen(lpStr));
638  }
639  if (LoadString(hInst, IDS_COLUMN_PID, lpStr, 80))
640  {
642  _tcsncpy(&lpHeader[columnRightPositions[1] + 2], lpStr, _tcslen(lpStr));
643  }
644  if (LoadString(hInst, IDS_COLUMN_CPU, lpStr, 80))
645  {
647  _tcsncpy(&lpHeader[columnRightPositions[2] + 2], lpStr, _tcslen(lpStr));
648  }
649  if (LoadString(hInst, IDS_COLUMN_MEM, lpStr, 80))
650  {
652  _tcsncpy(&lpHeader[columnRightPositions[3] + 2], lpStr, _tcslen(lpStr));
653  }
654  if (LoadString(hInst, IDS_COLUMN_PF, lpStr, 80))
655  {
657  _tcsncpy(&lpHeader[columnRightPositions[4] + 2], lpStr, _tcslen(lpStr));
658  }
659 
660  for (i = 0; i < columnRightPositions[5]; i++)
661  {
662  lpSeparator[i] = _T('-');
663  lpSeparatorUp[i] = _T('^');
664  lpSeparatorDown[i] = _T('v');
665  }
666  lpHeader[0] = _T('|');
667  lpSeparator[0] = _T('+');
668  lpSeparatorUp[0] = _T('^');
669  lpSeparatorDown[0] = _T('v');
670  for (i = 0; i < 6; i++)
671  {
676  }
677  lpHeader[columnRightPositions[5] + 1] = _T('\0');
678  lpSeparator[columnRightPositions[5] + 1] = _T('\0');
679  lpSeparatorUp[columnRightPositions[5] + 1] = _T('\0');
680  lpSeparatorDown[columnRightPositions[5] + 1] = _T('\0');
681 
682 
684  lpTitle[0] = _T('\0');
686  lpMemUnit[0] = _T('\0');
687  if (!LoadString(hInst, IDS_MENU, lpMenu, 80))
688  lpMenu[0] = _T('\0');
690  lpIdleProcess[0] = _T('\0');
691 
692  if (LoadString(hInst, IDS_MENU_QUIT, lpStr, 2))
693  KEY_QUIT = lpStr[0];
694  if (LoadString(hInst, IDS_MENU_KILL_PROCESS, lpStr, 2))
695  KEY_KILL = lpStr[0];
696  if (LoadString(hInst, IDS_YES, lpStr, 2))
697  KEY_YES = lpStr[0];
698  if (LoadString(hInst, IDS_NO, lpStr, 2))
699  KEY_NO = lpStr[0];
700 
702 
704  {
705  if (LoadString(hInst, IDS_CTM_GENERAL_ERR1, lpStr, 80))
706  _tprintf(lpStr);
707  return -1;
708  }
709 
710  if (GetConsoleMode(hStdin, &inConMode) == 0)
711  {
712  if (LoadString(hInst, IDS_CTM_GENERAL_ERR2, lpStr, 80))
713  _tprintf(lpStr);
714  return -1;
715  }
716 
717  if (GetConsoleMode(hStdout, &outConMode) == 0)
718  {
719  if (LoadString(hInst, IDS_CTM_GENERAL_ERR3, lpStr, 80))
720  _tprintf(lpStr);
721  return -1;
722  }
723 
724  SetConsoleMode(hStdin, 0); //FIXME: Should check for error!
725  SetConsoleMode(hStdout, 0); //FIXME: Should check for error!
726 
727  PerfInit();
728 
729  while (1)
730  {
731  DWORD numEvents;
732 
733  PerfDataRefresh();
734  DisplayScreen();
735 
736  /* WaitForSingleObject for console handles is not implemented in ROS */
739 
740  if (numEvents > 0)
741  {
742  if (ProcessKeys(numEvents) == TRUE)
743  break;
744  first = 0;
745  }
746  }
747 
748  RestoreConsole();
749  return 0;
750 }
#define realloc
Definition: debug_ros.c:6
DWORD columnRightPositions[6]
Definition: ctm.c:62
DWORD inConMode
Definition: ctm.c:59
static int argc
Definition: ServiceArgs.c:12
#define _tprintf
Definition: tchar.h:506
TCHAR lpHeader[80]
Definition: ctm.c:66
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
struct _PERFDATA * PPERFDATA
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define BACKGROUND_GREEN
Definition: wincon.h:44
double dbSystemTime
Definition: ctm.c:84
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:474
#define IDS_KILL_PROCESS_ERR1
Definition: resource.h:40
int ScreenLines
Definition: ctm.c:78
#define WideCharToMultiByte
Definition: compat.h:101
double dbIdleTime
Definition: ctm.c:82
int scrolled
Definition: ctm.c:93
#define IDS_COLUMN_NUMBER
Definition: resource.h:23
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define IDS_MENU
Definition: resource.h:35
BOOL WINAPI RevertToSelf(VOID)
Definition: security.c:1487
int ProcessKeys(int numEvents)
Definition: ctm.c:286
TCHAR lpMenu[80]
Definition: ctm.c:71
#define GetUserName
Definition: winbase.h:3668
#define CP_ACP
Definition: compat.h:99
void * PsaiRealloc(void *ptr, SIZE_T size)
Definition: ctm.c:102
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define free
Definition: debug_ros.c:5
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
const GLint * first
Definition: glext.h:5794
TCHAR lpSeparator[80]
Definition: ctm.c:63
#define IDS_COLUMN_MEM
Definition: resource.h:27
_TCHAR * _tcsncpy(_TCHAR *dst, const _TCHAR *src, size_t n)
Definition: tcsncpy.h:9
#define MB_PRECOMPOSED
Definition: winnls.h:278
#define HandleToUlong(h)
Definition: basetsd.h:79
TCHAR KEY_KILL
Definition: ctm.c:74
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
Definition: console.c:1801
TCHAR KEY_YES
Definition: ctm.c:75
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
LARGE_INTEGER liOldSystemTime
Definition: ctm.c:87
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
DWORD outConMode
Definition: ctm.c:60
#define TOKEN_IMPERSONATE
Definition: setypes.h:873
#define VK_DOWN
Definition: winuser.h:2202
#define VK_PRIOR
Definition: winuser.h:2195
PSYSTEM_PROCESSES FASTCALL PsaWalkNextProcess(IN PSYSTEM_PROCESSES CurrentProcess)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
ULONG CPUUsage
Definition: perfdata.h:37
void * PsaiMalloc(SIZE_T size)
Definition: ctm.c:101
#define argv
Definition: mplay32.c:18
#define NO_ERROR
Definition: dderror.h:5
SYSTEM_BASIC_INFORMATION SystemBasicInfo
Definition: ctm.c:95
LARGE_INTEGER CreateTime
Definition: extypes.h:887
void PerfInit()
Definition: ctm.c:405
int selection
Definition: ctm.c:92
PPERFDATA pPerfDataOld
Definition: ctm.c:89
void RestoreConsole()
Definition: ctm.c:131
#define FILE_SHARE_READ
Definition: compat.h:125
#define IDS_COLUMN_PF
Definition: resource.h:29
#define VK_NEXT
Definition: winuser.h:2196
#define IDS_MENU_QUIT
Definition: resource.h:36
#define IDS_YES
Definition: resource.h:16
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define IDS_COLUMN_MEM_UNIT
Definition: resource.h:28
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LARGE_INTEGER CurrentTime
Definition: extypes.h:846
#define VK_HOME
Definition: winuser.h:2198
TCHAR lpEmpty[80]
Definition: ctm.c:72
unsigned char * LPBYTE
Definition: typedefs.h:52
#define VK_UP
Definition: winuser.h:2200
#define ReadConsoleInput
Definition: wincon.h:766
long LONG
Definition: pedump.c:60
LARGE_INTEGER CreateTime
Definition: ctm.h:54
ULONG NonPagedPoolUsagePages
Definition: perfdata.h:46
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
#define GENERIC_WRITE
Definition: nt_native.h:90
#define KEY_EVENT
Definition: wincon.h:122
static PVOID ptr
Definition: dispmode.c:27
WCHAR ImageName[MAX_PATH]
Definition: perfdata.h:33
unsigned int idx
Definition: utils.c:41
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
#define IDS_KILL_PROCESS_ERR2
Definition: resource.h:41
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
#define IDS_NO
Definition: resource.h:17
BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
Definition: misc.c:152
ULONG WorkingSetSizeDelta
Definition: perfdata.h:41
#define STD_INPUT_HANDLE
Definition: winbase.h:264
ULONG ProcessCount
Definition: ctm.c:80
LARGE_INTEGER liOldKernelTime
Definition: ctm.c:86
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
TCHAR KEY_NO
Definition: ctm.c:75
unsigned int GetKeyPressed()
HANDLE hStdin
Definition: ctm.c:55
PSYSTEM_PROCESSES FASTCALL PsaWalkFirstProcess(IN PSYSTEM_PROCESSES ProcessesAndThreads)
ULONG HandleCount
Definition: perfdata.h:48
eMaj lines
Definition: tritemp.h:206
char TCHAR
Definition: xmlstorage.h:189
TCHAR lpSeparatorUp[80]
Definition: ctm.c:64
#define _T(x)
Definition: vfdio.h:22
GLsizeiptr size
Definition: glext.h:5919
#define SystemTimeInformation
Definition: ctm.h:57
#define TOKEN_QUERY
Definition: setypes.h:874
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG PageFaultCountDelta
Definition: perfdata.h:43
#define IDS_CTM_GENERAL_ERR2
Definition: resource.h:44
VOID NTAPI PsaFreeCapture(IN PVOID Capture)
Definition: processes.c:188
#define MAX_PATH
Definition: compat.h:26
int _tmain(int argc, char **argv)
Definition: ctm.c:617
TCHAR lpIdleProcess[80]
Definition: ctm.c:68
ULONG BasePriority
Definition: perfdata.h:47
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
void DisplayScreen()
Definition: ctm.c:141
#define IDS_KILL_PROCESS
Definition: resource.h:39
struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION * PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
NTSTATUS NTAPI PsaCaptureProcessesAndThreads(OUT PSYSTEM_PROCESSES *ProcessesAndThreads)
PPERFDATA pPerfData
Definition: ctm.c:90
UNICODE_STRING ImageName
Definition: extypes.h:890
#define IDS_CTM_GENERAL_ERR3
Definition: resource.h:45
#define TOKEN_DUPLICATE
Definition: setypes.h:872
ULONG WorkingSetSizeBytes
Definition: perfdata.h:39
WORD wColor
static const char * ImageName
Definition: image.c:34
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define IDS_IDLE_PROCESS
Definition: resource.h:3
BOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hConsoleInput, LPDWORD lpNumberOfEvents)
Definition: console.c:1637
HKEY key
Definition: reg.c:42
void PsaiFree(void *ptr)
Definition: ctm.c:103
GLenum GLsizei len
Definition: glext.h:6722
#define GENERIC_READ
Definition: compat.h:124
LARGE_INTEGER CPUTime
Definition: perfdata.h:38
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
ULONG ThreadCount
Definition: perfdata.h:49
Definition: bl.h:1338
ULONG ProcessCountOld
Definition: ctm.c:79
#define BACKGROUND_BLUE
Definition: wincon.h:43
int ProcPerScreen
Definition: ctm.c:77
#define _stprintf
Definition: utility.h:124
ULONG_PTR SIZE_T
Definition: typedefs.h:78
HANDLE ProcessId
Definition: perfdata.h:34
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define PROCESS_TERMINATE
Definition: pstypes.h:149
LARGE_INTEGER KernelTime
Definition: extypes.h:889
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:59
#define FOREGROUND_GREEN
Definition: wincon.h:40
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
void GetInputOutputHandles()
Definition: ctm.c:108
ULONG PeakWorkingSetSizeBytes
Definition: perfdata.h:40
#define IDS_MENU_KILL_PROCESS
Definition: resource.h:37
ULONG PageFaultCount
Definition: perfdata.h:42
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
#define IDS_APP_TITLE
Definition: resource.h:10
double dbKernelTime
Definition: ctm.c:83
#define FOREGROUND_RED
Definition: wincon.h:41
#define MultiByteToWideChar
Definition: compat.h:100
HANDLE hStdout
Definition: ctm.c:56
#define Li2Double(x)
Definition: perfdata.h:29
HANDLE events[2]
Definition: event.c:4
TCHAR lpMemUnit[3]
Definition: ctm.c:67
TCHAR KEY_QUIT
Definition: ctm.c:74
void PerfDataRefresh()
Definition: ctm.c:410
TCHAR lpTitle[80]
Definition: ctm.c:69
unsigned int ULONG
Definition: retypes.h:1
LARGE_INTEGER UserTime
Definition: extypes.h:888
HINSTANCE hInst
Definition: ctm.c:57
#define malloc
Definition: debug_ros.c:4
_Check_return_ long __cdecl labs(_In_ long x)
#define FOREGROUND_BLUE
Definition: wincon.h:39
#define IDS_COLUMN_PID
Definition: resource.h:25
#define WriteConsoleOutputCharacter
Definition: wincon.h:777
LARGE_INTEGER KernelTime
Definition: perfdata.h:55
ULONG VirtualMemorySizeBytes
Definition: perfdata.h:44
LARGE_INTEGER liOldIdleTime
Definition: ctm.c:85
#define memset(x, y, z)
Definition: compat.h:39
TCHAR lpSeparatorDown[80]
Definition: ctm.c:65
static SERVICE_STATUS status
Definition: service.c:31
LARGE_INTEGER UserTime
Definition: perfdata.h:54
#define IDS_COLUMN_IMAGENAME
Definition: resource.h:24
#define VK_END
Definition: winuser.h:2197
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo
Definition: ctm.c:97
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define LoadString
Definition: winuser.h:5720
#define IDS_COLUMN_CPU
Definition: resource.h:26
LONGLONG QuadPart
Definition: typedefs.h:112
Definition: path.c:42
HANDLE WINAPI CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode, CONST SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwFlags, LPVOID lpScreenBufferData)
Definition: console.c:2315
#define IDS_CTM_GENERAL_ERR1
Definition: resource.h:43
ULONG PagedPoolUsagePages
Definition: perfdata.h:45
Definition: ps.c:97