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);
537 if (!strnicmp(Locker, "\\\\afs\\", strlen("\\\\afs\\")))
538 strcpy(TargetDirectory, &Locker[strlen("\\\\afs\\")]);
540 strcpy(TargetDirectory, Locker);
543 #endif /* HAVE_HESOID */
550 ExitMutexHandle = CreateMutex(NULL, FALSE, "AfsExitEvent");
551 ChronMutexHandle = CreateMutex(NULL, FALSE, "WinTortureChronMutex");
552 MutexHandle = CreateMutex(NULL, FALSE, "WinTortureMutex");
553 FileMutexHandle = CreateMutex(NULL, FALSE, "WinTortureFileMutex");
554 OSMutexHandle = CreateMutex(NULL, FALSE, "WinTortureOSMutex");
556 for (i = 0; i < MAX_THREADS; i++)
561 sprintf(JobName, "%s%05d", "JOB", LogID);
562 JobHandle = CreateJobObject(NULL, JobName);
563 rc = AssignProcessToJobObject(JobHandle, GetCurrentProcess());
565 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
566 sprintf(FileName, "%s\\log%05d", WorkingDirectory, LogID);
567 CreateDirectory(FileName, NULL);
568 sprintf(FileName, "%s\\test", WorkingDirectory);
569 CreateDirectory(FileName, NULL);
572 sprintf(FileName, "%s\\log%05d\\Chron.log", WorkingDirectory, LogID);
573 DeleteFile(FileName);
576 sprintf(FileName, "%s\\log%05d\\%s", WorkingDirectory, LogID, HostName);
577 sprintf(command, "rmdir /S /Q %s > %s\\test\\test", FileName, WorkingDirectory);
580 ShutDownEventHandle = CreateEvent(NULL, TRUE, FALSE, "AfsShutdownEvent");
581 PauseEventHandle = CreateEvent(NULL, TRUE, FALSE, "AfsPauseEvent");
582 ContinueEventHandle = CreateEvent(NULL, TRUE, FALSE, "AfsContinueEvent");
586 if ((NumberOfIterations == 0) && (SecondsToRun == 0))
587 NumberOfIterations = 1;
588 else if (SecondsToRun != 0)
590 SecondsToRun += StartTime;
595 if (SecondsToRun != 0)
598 if (StartTime > SecondsToRun)
603 if (NumberOfIterations != 0)
605 if (LoopCount >= NumberOfIterations)
610 if (rc = WaitForSingleObject(ShutDownEventHandle, 0) == WAIT_OBJECT_0)
615 CurrentLoop = LoopCount;
618 printf("\nIteration %d started at: %s\n", LoopCount, tbuffer);
619 create_procs(HostName, CommandLine, TargetDirectory, AfsLocker, Locker,
620 HostName, NumberOfThreads, CurrentLoop, LogID);
622 printf("Iteration %d ended at: %s\n", LoopCount, tbuffer);
624 printf("Iteration %d lapse time: %ld seconds\n", LoopCount, EndTime - StartTime);
625 TotalTime += EndTime - StartTime;
626 sprintf(FileName, "%s\\log%05d\\IterationCount", WorkingDirectory, LogID);
627 WaitForSingleObject(MutexHandle, 20 * 1000);
628 if ((fp = fopen(FileName, "r")) != NULL)
630 fgets(buffer, sizeof(buffer), fp);
631 IterationCount = atoi(buffer);
635 fp = fopen(FileName, "w");
636 fprintf(fp, "%d\n", IterationCount);
638 ReleaseMutex(MutexHandle);
641 for (i = 0; i < MAX_THREADS; i++)
643 if (ThreadStatus[i] == 1)
648 if (i >= MAX_THREADS)
652 for (i = 0; i < MAX_THREADS; i++)
654 if (ThreadStatus[i] == 0)
662 printf("\nSleeping for 3 minutes for error recovery\n\n");
663 Sleep(3 * 60 * 1000);
669 sprintf(FileName, ".\\log%05d\\%s\\Master.log", LogID, HostName);
670 Mfp = fopen(FileName, "w+");
671 fprintf(Mfp, "Average Iteration Time = %.02f minutes\n\n", ((float)TotalTime/(float)(LoopCount))/60.0);
672 for (i = 0; i < NumberOfThreads; i++)
674 sprintf(FileName, ".\\log%05d\\%s\\Thread_%05d.log", LogID, HostName, i);
675 fp = fopen(FileName, "r");
678 fprintf(Mfp, "START OF THREAD %d\n\n", i);
679 while (fgets(buffer, 512, fp) != NULL)
681 fprintf(Mfp, "%s", buffer);
684 fprintf(Mfp, "END OF THREAD %d\n\n", i);
689 memset(WorkingDirectory, '\0', sizeof(WorkingDirectory));
690 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
692 sprintf(FileName, "%s\\log%05d\\%s\\%s", WorkingDirectory, LogID, HostName, "MasterProcessStatLog.log");
693 sprintf(MoveFileName, "%s\\log%05d\\%s\\%s", WorkingDirectory, LogID, HostName, "MasterProcessStatLogRaw.log");
694 BuildMasterStatLog(FileName, MoveFileName, NumberOfProcesses, NumberOfThreads, CommandLine, LoopCount,
695 TargetDirectory, -1);
697 // sprintf(DateTime, "%s-%04d%02d%02d-%02d%02d%02d", HostName,
702 // LocalTime.wMinute,
703 // LocalTime.wSecond);
704 // sprintf(command, "rename %s\\log%05d\\%s %s", WorkingDirectory, LogID, HostName, DateTime);
705 // rc = system(command);
707 WaitForSingleObject(ExitMutexHandle, 20 * 1000);
710 GetSystemTime(&SystemTime);
711 GetTimeZoneInformation(&TimeZoneInformation);
712 SystemTimeToTzSpecificLocalTime(&TimeZoneInformation, &SystemTime, &LocalTime);
714 NumberOfProcesses = 0;
715 sprintf(FileName, "%s\\log%05d\\ProcessCount", WorkingDirectory, LogID);
716 if ((fp = fopen(FileName, "r")) != NULL)
718 fgets(buffer, sizeof(buffer), fp);
719 NumberOfProcesses = atoi(buffer);
723 fp = fopen(FileName, "w");
724 fprintf(fp, "%d\n", NumberOfProcesses);
727 if (FindProcessCount("wintorture.exe", JobHandle) == 1)
729 NumberOfProcesses = 0;
730 sprintf(FileName, "%s\\log%05d\\ProcessCount", WorkingDirectory, LogID);
731 sprintf(MoveFileName, "%s\\log%05d\\ProcessCountRaw", WorkingDirectory, LogID);
732 if ((fp = fopen(FileName, "r")) != NULL)
734 fgets(buffer, sizeof(buffer), fp);
735 NumberOfProcesses = atoi(buffer);
737 MoveFile(FileName, MoveFileName);
741 sprintf(FileName, "%s\\log%05d\\IterationCount", WorkingDirectory, LogID);
742 sprintf(MoveFileName, "%s\\log%05d\\IterationCountRaw", WorkingDirectory, LogID);
743 if ((fp = fopen(FileName, "r")) != NULL)
745 fgets(buffer, sizeof(buffer), fp);
746 IterationCount = atoi(buffer);
748 MoveFile(FileName, MoveFileName);
751 sprintf(FileName, "%s\\log%05d\\%s", WorkingDirectory, LogID, "MasterStatLog.log");
752 sprintf(MoveFileName, "%s\\log%05d\\%s", WorkingDirectory, LogID, "MasterStatLogRaw.log");
753 BuildMasterStatLog(FileName, MoveFileName, NumberOfProcesses, NumberOfThreads,
754 CommandLine, IterationCount, TargetDirectory, -2);
755 sprintf(DateTime, "%s%05d-%04d%02d%02d-%02d%02d%02d", "log",
763 sprintf(command, "rename %s\\log%05d %s", WorkingDirectory, LogID, DateTime);
764 rc = system(command);
765 ResetEvent(ShutDownEventHandle);
766 ResetEvent(PauseEventHandle);
767 ResetEvent(ContinueEventHandle);
768 CloseHandle(ShutDownEventHandle);
769 CloseHandle(PauseEventHandle);
770 CloseHandle(ContinueEventHandle);
774 ReleaseMutex(ExitMutexHandle);
775 CloseHandle(JobHandle);
779 int ProcessNameAndID(DWORD processID, char *ProcessName, HANDLE JobHandle)
781 char szProcessName[1024] = "unknown";
783 char WorkingDirectory[512];
787 memset(WorkingDirectory, '\0', sizeof(WorkingDirectory));
788 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
789 strcat(WorkingDirectory, "\\");
791 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
797 if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
799 memset(szProcessName, '\0', sizeof(szProcessName));
800 GetModuleBaseName(hProcess, hMod, szProcessName, sizeof(szProcessName));
801 if (!stricmp(szProcessName, ProcessName))
803 memset(FileName, '\0', sizeof(FileName));
804 if (GetModuleFileNameEx(hProcess, hMod, FileName, sizeof(FileName) - 1))
806 if (!strnicmp(WorkingDirectory, FileName, strlen(WorkingDirectory)))
814 CloseHandle(hProcess);
818 DWORD FindProcessCount(char *ProcessName, HANDLE JobHandle)
820 DWORD aProcesses[8092];
826 JOBOBJECT_BASIC_PROCESS_ID_LIST IdList;
828 rc = QueryInformationJobObject(JobHandle, JobObjectBasicProcessIdList, &IdList, sizeof(IdList), NULL);
829 return(IdList.NumberOfAssignedProcesses);
831 if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
835 cProcesses = cbNeeded / sizeof(DWORD);
837 for (i = 0; i < cProcesses; i++)
840 // Count += ProcessNameAndID(aProcesses[i], ProcessName, JobHandle);
846 char *_progname(char *nargv0)
850 tmp = strrchr(nargv0, '/');
858 #define BADCH (int)'?'
859 #define BADARG (int)':'
862 int getopt(int nargc, char *nargv[], char *ostr)
864 static char *__progname = 0;
865 static char *place = EMSG; /* option letter processing */
866 char *oli; /* option letter list index */
868 __progname = __progname?__progname:_progname(*nargv);
870 if (optreset || !*place)
873 if (optind >= nargc || *(place = nargv[optind]) != '-')
878 if (place[1] && *++place == '-' && place[1] == '\0')
885 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr, optopt)))
887 if (optopt == (int)'-')
891 if (opterr && *ostr != ':')
892 (void)fprintf(stderr, "%s: illegal option -- %c\n", __progname, optopt);
905 else if (nargc <= ++optind)
911 (void)fprintf(stderr, "%s: option requires an argument -- %c\n", __progname, optopt);
915 optarg = nargv[optind];