1 //#define _WIN32_WINNT 0x0500
8 #include "ResolveLocker.h"
9 extern int ResolveLocker(USER_OPTIONS *attachOption);
10 extern void GetLockerInfo(char *Locker, char *Path);
11 #endif /* HAVE_HESOID */
13 #define MAX_THREADS 100
21 extern void LogStats(char *FileName, int ToLog, int Iteration, int NumberOfProcesses, int NumberOfThreads,
22 char *HostName, int ProcessNumber, struct cmd_struct CommandInfo[],
23 char *CommandLine, char *TargetDirectory);
24 extern int UpdateMasterLog(char *FileName, struct cmd_struct CommandInfo[]);
25 extern int BuildMasterStatLog(char *FileName, char *MoveFileName, int NumberOfProcesses,
26 int NumberOfThreads, char *CommandLine, int LoopCount,
27 char *TargetDirectory, int ProcessNumber);
28 extern void LogMessage(int ProcessNumber, char *HostName, char *FileName, char *message, int LogID);
30 DWORD WINAPI StressTestThread(LPVOID lpThreadParameter);
31 int getopt(int, char**, char*);
32 DWORD FindProcessCount(char *ProcessName, HANDLE JobHandle);
33 void show_results(char *CommandLine, char *TargetDirectory, struct cmd_struct CommandInfo[],
34 char *HostName, int NumberOfThreads, int CurrentLoop, int LogID);
36 char *ClientText = "streamfiles.txt";
37 char PathToSecondDir[256];
38 int ThreadStatus[MAX_HANDLES];
40 static int BufferSize = 256*1024;
47 HANDLE FileMutexHandle;
48 HANDLE ChronMutexHandle;
50 HANDLE ShutDownEventHandle;
51 HANDLE PauseEventHandle;
52 HANDLE ContinueEventHandle;
53 EXIT_STATUS ExitStatus[MAX_HANDLES];
55 double create_procs(char *Hostname, char *CommandLine, char *TargetDirectory,
56 char *AfsLocker, char *Locker, char *HostName,
57 int NumberOfThreads, int CurrentLoop, int LogID)
64 HANDLE hEventHandle[MAX_HANDLES];
65 HANDLE hThreadHandle[MAX_HANDLES];
66 DWORD dwThreadID[MAX_HANDLES];
67 struct cmd_struct *CommandInfo;
68 CRITICAL_SECTION CriticalSection;
69 PARAMETERLIST *pParameterList[MAX_HANDLES];
71 USER_OPTIONS attachOption;
74 InitializeCriticalSection(&CriticalSection);
75 for (i = 0; i < MAX_HANDLES; i++)
77 hEventHandle[i] = NULL;
78 hThreadHandle[i] = NULL;
79 pParameterList[i] = NULL;
84 CommandInfo = calloc(1, sizeof(struct cmd_struct) * (CMD_MAX_CMD + 1) * NumberOfThreads);
87 for (i = 0; i < NumberOfThreads; i++)
91 if (ThreadStatus[count] == 0)
94 sprintf(EventName, "%d%sEvent%05d", ProcessID, HostName, count);
95 hEventHandle[count] = CreateEvent(NULL, FALSE, FALSE, EventName);
96 if (hEventHandle[count] == NULL)
98 ResetEvent(hEventHandle[count]);
100 pParameterList[count] = calloc(1, sizeof(PARAMETERLIST));
101 pParameterList[count]->ProcessNumber = count;
102 pParameterList[count]->CommandInfo = (struct cmd_struct *)(CommandInfo + (i * (CMD_MAX_CMD + 1)));
103 pParameterList[count]->BufferSize = BufferSize;
104 pParameterList[count]->PrintStats = PrintStats;
105 pParameterList[count]->CurrentLoop = CurrentLoop;
106 pParameterList[count]->AfsTrace = AfsTrace;
107 pParameterList[count]->TargetDirectory = TargetDirectory;
108 pParameterList[count]->pExitStatus = &ExitStatus[i];
109 pParameterList[count]->pThreadStatus = &ThreadStatus[i];
110 pParameterList[count]->CommandLine = CommandLine;
111 pParameterList[count]->ClientText = ClientText;
112 pParameterList[count]->PathToSecondDir = PathToSecondDir;
113 pParameterList[count]->AfsLocker = AfsLocker;
114 pParameterList[count]->HostName = HostName;
115 pParameterList[count]->ProcessID = ProcessID;;
116 pParameterList[count]->LogID = LogID;;
118 ThreadStatus[count] = 0;
119 hThreadHandle[count] = CreateThread(NULL, 0, &StressTestThread, (LPVOID)pParameterList[count], CREATE_SUSPENDED, &dwThreadID[count]);
120 if (hThreadHandle[count] != NULL)
122 ResumeThread(hThreadHandle[count]);
123 ThreadStatus[count] = 1;
128 CloseHandle(hEventHandle[count]);
129 if (pParameterList[count] != NULL)
130 free(pParameterList[count]);
131 pParameterList[count] = NULL;
132 hThreadHandle[count] = NULL;
133 hEventHandle[count] = NULL;
138 for (i = 0; i < MAX_HANDLES; i++)
140 if (hEventHandle[i] != NULL)
148 memset(&attachOption, '\0', sizeof(attachOption));
149 strcpy(attachOption.Locker, Locker);
150 strcpy(attachOption.type, "locker");
151 if (rc = ResolveLocker(&attachOption))
153 if (!stricmp(attachOption.type, "AFS"))
155 printf("Unable to attach locker %s - AFS is not supported\n", Locker);
158 strcpy(AfsLocker, attachOption.SubMount);
159 memset(&attachOption, '\0', sizeof(attachOption));
160 strcpy(attachOption.Locker, Locker);
161 strcpy(attachOption.type, "locker");
162 if (rc = attach(attachOption, 0, 0, Locker))
164 printf("Unable to attach locker %s\n", Locker);
169 #endif /* HAVE_HESOID */
171 status = WaitForMultipleObjects(count, hEventHandle, TRUE, INFINITE);
172 for (i = 0; i < MAX_HANDLES; i++)
174 if (hEventHandle[i] != NULL)
175 CloseHandle(hEventHandle[i]);
176 if (pParameterList[i] != NULL)
177 free(pParameterList[i]);
178 pParameterList[i] = NULL;
179 hEventHandle[i] = NULL;
182 for (i = 0; i < NumberOfThreads; i++)
187 if (strlen(ExitStatus[i].Reason))
189 sprintf(temp, "Thread %0d exited with reason: %s", i, ExitStatus[i].Reason);
193 sprintf(temp, "Thread %0d completed\n", i);
197 sprintf(FileName, "Thread_%05d.log", i);
198 LogMessage(i, HostName, FileName, temp, LogID);
199 sprintf(temp, "Ended Iteration %0d\n\n", CurrentLoop);
200 LogMessage(i, HostName, FileName, temp, LogID);
201 CloseHandle(hEventHandle[i]);
203 show_results(CommandLine, TargetDirectory, CommandInfo, HostName, NumberOfThreads, CurrentLoop, LogID);
205 DeleteCriticalSection(&CriticalSection);
210 static void usage(void)
213 fprintf(stderr, "usage: wintorture [options]\n");
214 fprintf(stderr, "where options can be:\n");
215 fprintf(stderr, "\t-b Create a chronological log.\n");
216 fprintf(stderr, "\t-c <txt> Specifies the script txt file to use.\n");
217 fprintf(stderr, "\t-e End thread processing on an error.\n");
218 fprintf(stderr, "\t-f <name> Target directory name.\n");
219 fprintf(stderr, "\t-i <num> Number of iterations of the stress test to run.\n");
220 fprintf(stderr, "\t This option will override the -m option.\n");
222 fprintf(stderr, "\t-l <path> AFS locker or AFS submount in which to create the target directory.\n");
223 #endif /* HAVE_HESOID */
224 fprintf(stderr, "\t-m <num> The number of minutes to run the stress test.\n");
225 fprintf(stderr, "\t This option will override the -i option.\n");
226 fprintf(stderr, "\t-n <num> The number of threads to run.\n");
227 fprintf(stderr, "\t-p <path> UNC path to second directory.\n");
228 fprintf(stderr, "\t-s Output stats.\n");
229 fprintf(stderr, "\t-t Do AFS trace logging.\n");
230 fprintf(stderr, "\t-u <UNC> UNC path to target directory.\n");
231 fprintf(stderr, "\t-v Turn on verbose mode.\n");
232 fprintf(stderr, "\nNOTE: The switches are not case sensitive. You\n");
233 fprintf(stderr, "\n may use either upper or lower case letters.\n\n");
236 void show_results(char *CommandLine, char *TargetDirectory, struct cmd_struct *CommandInfo,
237 char *HostName, int NumberOfThreads, int CurrentLoop, int LogID)
239 struct cmd_struct TotalCommandInfo[CMD_MAX_CMD + 1];
242 unsigned grand_total = 0;
244 char WorkingDirectory[512];
245 struct cmd_struct *FinalCmdInfo;
247 for (j = 0; j <= CMD_MAX_CMD; j++) {
248 TotalCommandInfo[j].count = 0;
249 TotalCommandInfo[j].min_sec = 0;
250 TotalCommandInfo[j].max_sec = 0;
251 TotalCommandInfo[j].MilliSeconds = 0;
252 TotalCommandInfo[j].total_sec = 0;
253 TotalCommandInfo[j].total_sum_of_squares = 0;
254 TotalCommandInfo[j].ErrorCount = 0;
255 TotalCommandInfo[j].ErrorTime = 0;
258 memset(ExitStatus, '\0', sizeof(ExitStatus[0]) * MAX_HANDLES);
260 for (j = 0; j < NumberOfThreads; j++)
262 FinalCmdInfo = CommandInfo + (j * (CMD_MAX_CMD + 1));
264 for (i = 0; i <= CMD_MAX_CMD; i++)
266 TotalCommandInfo[i].count += FinalCmdInfo[i].count;
267 TotalCommandInfo[i].total_sec += FinalCmdInfo[i].total_sec;
268 TotalCommandInfo[i].total_sum_of_squares += FinalCmdInfo[i].total_sum_of_squares;
269 TotalCommandInfo[i].ErrorCount += FinalCmdInfo[i].ErrorCount;
270 TotalCommandInfo[i].ErrorTime += FinalCmdInfo[i].ErrorTime;
271 grand_total += FinalCmdInfo[j].total_sec;
272 if (!TotalCommandInfo[i].min_sec || (TotalCommandInfo[i].min_sec > FinalCmdInfo[i].min_sec))
273 TotalCommandInfo[i].min_sec = FinalCmdInfo[i].min_sec;
274 if (TotalCommandInfo[i].max_sec < FinalCmdInfo[i].max_sec)
275 TotalCommandInfo[i].max_sec = FinalCmdInfo[i].max_sec;
280 memset(WorkingDirectory, '\0', sizeof(WorkingDirectory));
281 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
282 sprintf(FileName, "%s\\log%05d\\%s\\ProcessStats.log", WorkingDirectory, LogID, HostName);
285 LogStats(FileName, 0, CurrentLoop, 1, NumberOfThreads, HostName, -1, TotalCommandInfo,
286 CommandLine, TargetDirectory);
287 LogStats(FileName, 1, CurrentLoop, 1, NumberOfThreads, HostName, -1, TotalCommandInfo,
288 CommandLine, TargetDirectory);
290 sprintf(FileName, "%s\\log%05d\\%s", WorkingDirectory, LogID, "MasterStatLog.log");
291 UpdateMasterLog(FileName, TotalCommandInfo);
292 sprintf(FileName, "%s\\log%05d\\%s\\%s", WorkingDirectory, LogID, HostName, "MasterProcessStatLog.log");
293 UpdateMasterLog(FileName, TotalCommandInfo);
297 int main(int argc, char *argv[])
302 int NumberOfIterations;
303 int StressTestUsed = 0;
307 int NumberOfProcesses;
323 char MoveFileName[256];
327 char WorkingDirectory[512];
328 char CommandLine[512];
329 char TargetDirectory[512];
333 SYSTEMTIME SystemTime;
334 SYSTEMTIME LocalTime;
335 TIME_ZONE_INFORMATION TimeZoneInformation;
336 HANDLE ExitMutexHandle;
340 memset(HostName, '\0', sizeof(HostName));
341 memset(PathToSecondDir, '\0', sizeof(PathToSecondDir));
342 memset(Locker, '\0', sizeof(Locker));
344 NumberOfIterations = 0;
351 NumberOfProcesses = 1;
356 while ((opt = getopt(argc, argv, "A:a:BbC:c:D:d:EeF:f:G:g:I:i:L:l:M:m:N:n:P:p:SsTtU:u:Vv")) != EOF)
375 NumberOfProcesses = atoi(optarg);
383 strcpy(HostName, optarg);
384 for (i = 0; i < (int)strlen(HostName); i++)
386 if ((HostName[i] == '\\') || (HostName[i] == '/'))
388 printf("\nInvalid -F usage...Subdirectories not allowed\n\n");
397 LogID = atoi(optarg);
402 NumberOfIterations = atoi(optarg);
403 if (NumberOfIterations < 0)
404 NumberOfIterations = 0;
409 strcpy(Locker, optarg);
412 #endif /* HAVE_HESOID */
415 NumberOfIterations = 0;
416 SecondsToRun = atoi(optarg) * 60;
417 if (SecondsToRun < 0)
422 NumberOfThreads = atoi(optarg);
426 strcpy(PathToSecondDir, optarg);
427 for(p = PathToSecondDir; *p; p++)
444 strcpy(Locker, optarg);
457 if (strlen(HostName) == 0)
459 printf("You must use the -f option to specify a target directory\n\n");
463 if (strlen(Locker) == 0)
465 printf("You must use either the -u or the -l option\n\n");
470 memset(CommandLine, '\0', sizeof(CommandLine));
471 for (i = 1; i < argc; i++)
475 if (!stricmp(argv[i], "-f"))
479 strcpy(temp, argv[i + 1]);
480 temp[strlen(temp) - 5] = '\0';
481 strcat(CommandLine, argv[i]);
482 strcat(CommandLine, " ");
483 strcat(CommandLine, temp);
484 strcat(CommandLine, " ");
489 strcat(CommandLine, argv[i]);
490 strcat(CommandLine, " ");
496 if (strlen(Locker) == 0)
503 for(p = Locker; *p; p++)
514 sprintf(AfsLocker, "\\\\afs\\%s", Locker);
515 memset(buffer, '\0', sizeof(buffer));
516 GetLockerInfo(Locker, buffer);
517 if (strlen(buffer) != 0)
519 sPtr = strstr(buffer, "/afs/");
520 sPtr += strlen("/afs/");
521 strcpy(TargetDirectory, sPtr);
522 sPtr = strchr(TargetDirectory, ' ');
525 while ((sPtr = strchr(TargetDirectory, '/')) != NULL)
530 strcpy(TargetDirectory, Locker);
535 #endif /* HAVE_HESOID */
536 strcpy(AfsLocker, Locker);
538 /* jaltman - this makes no sense. why strip off the server name and leave
539 * an absolute path on the local disk?
541 if (!strnicmp(Locker, "\\\\afs\\", strlen("\\\\afs\\")))
542 strcpy(TargetDirectory, &Locker[strlen("\\\\afs\\")]);
545 strcpy(TargetDirectory, Locker);
548 #endif /* HAVE_HESOID */
555 ExitMutexHandle = CreateMutex(NULL, FALSE, "AfsExitEvent");
556 ChronMutexHandle = CreateMutex(NULL, FALSE, "WinTortureChronMutex");
557 MutexHandle = CreateMutex(NULL, FALSE, "WinTortureMutex");
558 FileMutexHandle = CreateMutex(NULL, FALSE, "WinTortureFileMutex");
559 OSMutexHandle = CreateMutex(NULL, FALSE, "WinTortureOSMutex");
561 for (i = 0; i < MAX_THREADS; i++)
566 sprintf(JobName, "%s%05d", "JOB", LogID);
567 JobHandle = CreateJobObject(NULL, JobName);
568 rc = AssignProcessToJobObject(JobHandle, GetCurrentProcess());
570 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
571 sprintf(FileName, "%s\\log%05d", WorkingDirectory, LogID);
572 CreateDirectory(FileName, NULL);
573 sprintf(FileName, "%s\\test", WorkingDirectory);
574 CreateDirectory(FileName, NULL);
577 sprintf(FileName, "%s\\log%05d\\Chron.log", WorkingDirectory, LogID);
578 DeleteFile(FileName);
581 sprintf(FileName, "%s\\log%05d\\%s", WorkingDirectory, LogID, HostName);
582 sprintf(command, "rmdir /S /Q %s > %s\\test\\test", FileName, WorkingDirectory);
585 ShutDownEventHandle = CreateEvent(NULL, TRUE, FALSE, "AfsShutdownEvent");
586 PauseEventHandle = CreateEvent(NULL, TRUE, FALSE, "AfsPauseEvent");
587 ContinueEventHandle = CreateEvent(NULL, TRUE, FALSE, "AfsContinueEvent");
591 if ((NumberOfIterations == 0) && (SecondsToRun == 0))
592 NumberOfIterations = 1;
593 else if (SecondsToRun != 0)
595 SecondsToRun += StartTime;
600 if (SecondsToRun != 0)
603 if (StartTime > SecondsToRun)
608 if (NumberOfIterations != 0)
610 if (LoopCount >= NumberOfIterations)
615 if (rc = WaitForSingleObject(ShutDownEventHandle, 0) == WAIT_OBJECT_0)
620 CurrentLoop = LoopCount;
623 printf("\nIteration %d started at: %s\n", LoopCount, tbuffer);
624 create_procs(HostName, CommandLine, TargetDirectory, AfsLocker, Locker,
625 HostName, NumberOfThreads, CurrentLoop, LogID);
627 printf("Iteration %d ended at: %s\n", LoopCount, tbuffer);
629 printf("Iteration %d lapse time: %ld seconds\n", LoopCount, EndTime - StartTime);
630 TotalTime += EndTime - StartTime;
631 sprintf(FileName, "%s\\log%05d\\IterationCount", WorkingDirectory, LogID);
632 WaitForSingleObject(MutexHandle, 20 * 1000);
633 if ((fp = fopen(FileName, "r")) != NULL)
635 fgets(buffer, sizeof(buffer), fp);
636 IterationCount = atoi(buffer);
640 fp = fopen(FileName, "w");
641 fprintf(fp, "%d\n", IterationCount);
643 ReleaseMutex(MutexHandle);
646 for (i = 0; i < MAX_THREADS; i++)
648 if (ThreadStatus[i] == 1)
653 if (i >= MAX_THREADS)
657 for (i = 0; i < MAX_THREADS; i++)
659 if (ThreadStatus[i] == 0)
667 printf("\nSleeping for 3 minutes for error recovery\n\n");
668 Sleep(3 * 60 * 1000);
674 sprintf(FileName, ".\\log%05d\\%s\\Master.log", LogID, HostName);
675 Mfp = fopen(FileName, "w+");
676 fprintf(Mfp, "Average Iteration Time = %.02f minutes\n\n", ((float)TotalTime/(float)(LoopCount))/60.0);
677 for (i = 0; i < NumberOfThreads; i++)
679 sprintf(FileName, ".\\log%05d\\%s\\Thread_%05d.log", LogID, HostName, i);
680 fp = fopen(FileName, "r");
683 fprintf(Mfp, "START OF THREAD %d\n\n", i);
684 while (fgets(buffer, 512, fp) != NULL)
686 fprintf(Mfp, "%s", buffer);
689 fprintf(Mfp, "END OF THREAD %d\n\n", i);
694 memset(WorkingDirectory, '\0', sizeof(WorkingDirectory));
695 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
697 sprintf(FileName, "%s\\log%05d\\%s\\%s", WorkingDirectory, LogID, HostName, "MasterProcessStatLog.log");
698 sprintf(MoveFileName, "%s\\log%05d\\%s\\%s", WorkingDirectory, LogID, HostName, "MasterProcessStatLogRaw.log");
699 BuildMasterStatLog(FileName, MoveFileName, NumberOfProcesses, NumberOfThreads, CommandLine, LoopCount,
700 TargetDirectory, -1);
702 // sprintf(DateTime, "%s-%04d%02d%02d-%02d%02d%02d", HostName,
707 // LocalTime.wMinute,
708 // LocalTime.wSecond);
709 // sprintf(command, "rename %s\\log%05d\\%s %s", WorkingDirectory, LogID, HostName, DateTime);
710 // rc = system(command);
712 WaitForSingleObject(ExitMutexHandle, 20 * 1000);
715 GetSystemTime(&SystemTime);
716 GetTimeZoneInformation(&TimeZoneInformation);
717 SystemTimeToTzSpecificLocalTime(&TimeZoneInformation, &SystemTime, &LocalTime);
719 NumberOfProcesses = 0;
720 sprintf(FileName, "%s\\log%05d\\ProcessCount", WorkingDirectory, LogID);
721 if ((fp = fopen(FileName, "r")) != NULL)
723 fgets(buffer, sizeof(buffer), fp);
724 NumberOfProcesses = atoi(buffer);
728 fp = fopen(FileName, "w");
729 fprintf(fp, "%d\n", NumberOfProcesses);
732 if (FindProcessCount("wintorture.exe", JobHandle) == 1)
734 NumberOfProcesses = 0;
735 sprintf(FileName, "%s\\log%05d\\ProcessCount", WorkingDirectory, LogID);
736 sprintf(MoveFileName, "%s\\log%05d\\ProcessCountRaw", WorkingDirectory, LogID);
737 if ((fp = fopen(FileName, "r")) != NULL)
739 fgets(buffer, sizeof(buffer), fp);
740 NumberOfProcesses = atoi(buffer);
742 MoveFile(FileName, MoveFileName);
746 sprintf(FileName, "%s\\log%05d\\IterationCount", WorkingDirectory, LogID);
747 sprintf(MoveFileName, "%s\\log%05d\\IterationCountRaw", WorkingDirectory, LogID);
748 if ((fp = fopen(FileName, "r")) != NULL)
750 fgets(buffer, sizeof(buffer), fp);
751 IterationCount = atoi(buffer);
753 MoveFile(FileName, MoveFileName);
756 sprintf(FileName, "%s\\log%05d\\%s", WorkingDirectory, LogID, "MasterStatLog.log");
757 sprintf(MoveFileName, "%s\\log%05d\\%s", WorkingDirectory, LogID, "MasterStatLogRaw.log");
758 BuildMasterStatLog(FileName, MoveFileName, NumberOfProcesses, NumberOfThreads,
759 CommandLine, IterationCount, TargetDirectory, -2);
760 sprintf(DateTime, "%s%05d-%04d%02d%02d-%02d%02d%02d", "log",
768 sprintf(command, "rename %s\\log%05d %s", WorkingDirectory, LogID, DateTime);
769 rc = system(command);
770 ResetEvent(ShutDownEventHandle);
771 ResetEvent(PauseEventHandle);
772 ResetEvent(ContinueEventHandle);
773 CloseHandle(ShutDownEventHandle);
774 CloseHandle(PauseEventHandle);
775 CloseHandle(ContinueEventHandle);
779 ReleaseMutex(ExitMutexHandle);
780 CloseHandle(JobHandle);
784 int ProcessNameAndID(DWORD processID, char *ProcessName, HANDLE JobHandle)
786 char szProcessName[1024] = "unknown";
788 char WorkingDirectory[512];
792 memset(WorkingDirectory, '\0', sizeof(WorkingDirectory));
793 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
794 strcat(WorkingDirectory, "\\");
796 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
802 if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
804 memset(szProcessName, '\0', sizeof(szProcessName));
805 GetModuleBaseName(hProcess, hMod, szProcessName, sizeof(szProcessName));
806 if (!stricmp(szProcessName, ProcessName))
808 memset(FileName, '\0', sizeof(FileName));
809 if (GetModuleFileNameEx(hProcess, hMod, FileName, sizeof(FileName) - 1))
811 if (!strnicmp(WorkingDirectory, FileName, strlen(WorkingDirectory)))
819 CloseHandle(hProcess);
823 DWORD FindProcessCount(char *ProcessName, HANDLE JobHandle)
825 DWORD aProcesses[8092];
831 JOBOBJECT_BASIC_PROCESS_ID_LIST IdList;
833 rc = QueryInformationJobObject(JobHandle, JobObjectBasicProcessIdList, &IdList, sizeof(IdList), NULL);
834 return(IdList.NumberOfAssignedProcesses);
836 if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
840 cProcesses = cbNeeded / sizeof(DWORD);
842 for (i = 0; i < cProcesses; i++)
845 // Count += ProcessNameAndID(aProcesses[i], ProcessName, JobHandle);
851 char *_progname(char *nargv0)
855 tmp = strrchr(nargv0, '/');
863 #define BADCH (int)'?'
864 #define BADARG (int)':'
867 int getopt(int nargc, char *nargv[], char *ostr)
869 static char *__progname = 0;
870 static char *place = EMSG; /* option letter processing */
871 char *oli; /* option letter list index */
873 __progname = __progname?__progname:_progname(*nargv);
875 if (optreset || !*place)
878 if (optind >= nargc || *(place = nargv[optind]) != '-')
883 if (place[1] && *++place == '-' && place[1] == '\0')
890 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr, optopt)))
892 if (optopt == (int)'-')
896 if (opterr && *ostr != ':')
897 (void)fprintf(stderr, "%s: illegal option -- %c\n", __progname, optopt);
910 else if (nargc <= ++optind)
916 (void)fprintf(stderr, "%s: option requires an argument -- %c\n", __progname, optopt);
920 optarg = nargv[optind];