-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListProcessesConsole.c
52 lines (46 loc) · 1.36 KB
/
ListProcessesConsole.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
#include <psapi.h>
#include <processthreadsapi.h>
#include <shlwapi.h>
#include <locale.h>
#include <tlhelp32.h>
#include "ListProcesses.h"
int main(int argc, char* argv[])
{
int (*linesFunc)(int maxItems, CHAR **linesToFill) = list_processes_run_no_sort;
for(int i = 0; i < argc; i++)
{
if(strcmp(argv[i], "--sort") == 0)
{
if(i + 1 < argc)
{
i++;
if(strcmp(argv[i], "cpu") == 0)
{
linesFunc = list_processes_run_sorted_by_cpu;
}
else if(strcmp(argv[i], "privateBytes") == 0)
{
linesFunc = list_processes_run_sorted_by_private_bytes;
}
else if(strcmp(argv[i], "workingSet") == 0)
{
linesFunc = list_processes_run_sorted_by_working_set;
}
else if(strcmp(argv[i], "pid") == 0)
{
linesFunc = list_processes_run_sorted_by_pid;
}
}
}
}
CHAR *lines[4096];
int numberOfResults = linesFunc(4096, lines);
for(int i = 0; i < numberOfResults; i++)
{
printf("%s\n", lines[i]);
}
return 0;
}