Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name:
  4. kill.c
  5. Abstract:
  6. This module implements a working set empty application.
  7. Author:
  8. Lou Perazzoli (loup) 20-May-1994
  9. Wesley Witt (wesw) 20-May-1994
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "pch.h"
  14. #pragma hdrstop
  15. DWORD pid;
  16. CHAR pname[MAX_PATH];
  17. TASK_LIST tlist[MAX_TASKS];
  18. CHAR System[] = "System";
  19. VOID GetCommandLineArgs(VOID);
  20. int __cdecl
  21. main(
  22. int argc,
  23. char *argv[]
  24. )
  25. {
  26. DWORD i;
  27. DWORD numTasks;
  28. int rval = 0;
  29. TASK_LIST_ENUM te;
  30. char tname[PROCESS_SIZE];
  31. LPSTR p;
  32. GetCommandLineArgs();
  33. if (pid == 0 && pname[0] == 0) {
  34. printf( "missing pid or task name\n" );
  35. return 1;
  36. }
  37. //
  38. // let's be god
  39. //
  40. EnableDebugPriv();
  41. if (pid) {
  42. if (!EmptyProcessWorkingSet( pid )) {
  43. printf( "could not empty working set for process #%d\n", pid );
  44. return 1;
  45. }
  46. return 0;
  47. }
  48. //
  49. // get the task list for the system
  50. //
  51. numTasks = GetTaskList( tlist, MAX_TASKS );
  52. //
  53. // enumerate all windows and try to get the window
  54. // titles for each task
  55. //
  56. te.tlist = tlist;
  57. te.numtasks = numTasks;
  58. GetWindowTitles( &te );
  59. for (i=0; i<numTasks; i++) {
  60. strcpy( tname, tlist[i].ProcessName );
  61. p = strchr( tname, '.' );
  62. if (p) {
  63. p[0] = '\0';
  64. }
  65. if (MatchPattern( tname, pname )) {
  66. tlist[i].flags = TRUE;
  67. } else if (MatchPattern( tlist[i].ProcessName, pname )) {
  68. tlist[i].flags = TRUE;
  69. } else if (MatchPattern( tlist[i].WindowTitle, pname )) {
  70. tlist[i].flags = TRUE;
  71. }
  72. }
  73. for (i=0; i<numTasks; i++) {
  74. if (tlist[i].flags) {
  75. if (!EmptyProcessWorkingSet( tlist[i].dwProcessId )) {
  76. printf( "could not empty working set for process #%d [%s]\n", tlist[i].dwProcessId, tlist[i].ProcessName );
  77. rval = 1;
  78. }
  79. }
  80. }
  81. if (MatchPattern(System, pname )) {
  82. if (!EmptySystemWorkingSet()) {
  83. printf( "could not empty working set for process #%d [%s]\n",0,&System );
  84. }
  85. }
  86. return rval;
  87. }
  88. VOID
  89. GetCommandLineArgs(
  90. VOID
  91. )
  92. {
  93. char *lpstrCmd;
  94. UCHAR ch;
  95. char *p = pname;
  96. pid = 0;
  97. *p = '\0';
  98. lpstrCmd = GetCommandLine();
  99. // skip over program name
  100. do {
  101. ch = *lpstrCmd++;
  102. }
  103. while (ch != ' ' && ch != '\t' && ch != '\0');
  104. // skip over any following white space
  105. while (isspace(ch)) {
  106. ch = *lpstrCmd++;
  107. }
  108. if (isdigit(ch)) {
  109. while (isdigit(ch)) {
  110. pid = pid * 10 + ch - '0';
  111. ch = *lpstrCmd++;
  112. }
  113. }
  114. else {
  115. while (ch) {
  116. *p++ = ch;
  117. ch = *lpstrCmd++;
  118. }
  119. *p = '\0';
  120. _strupr( pname );
  121. }
  122. return;
  123. }