-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
79 lines (75 loc) · 1.97 KB
/
Copy pathmain.c
File metadata and controls
79 lines (75 loc) · 1.97 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "command_parser.h"
#include "fetch_process.h"
//the main loop for the program
int main(int argc, char *argv[])
{
flags *activeFlags = parsecommand(argc, argv);
if (activeFlags == NULL)
{
return 0;
}
if (activeFlags->fail == 1)
{
fprintf(stderr, "CUps -e | -u <UID> | -p <PID>\n");
return 0;
}
if (activeFlags->selEf)
{
printf("option e\n");
printf(" PID ProcessName State PPID SESSIONID\n");
fetchProcess();
return 0;
}
else
{
if (activeFlags->selUs)
{
ProcessList *processNode = NULL;
printf("option u\n");
if (activeFlags->uid)
{
printf("UID %s\n", activeFlags->uid);
processNode = fetchProcessList();
if (processNode == NULL)
{
fprintf(stderr, "No current running processes");
return 0;
}
printPIDList(processNode);
return 0;
}
else
{
printf("Also provide a UID\n");
return 0;
}
}
else
{
if (activeFlags->selPr)
{
printf("option p\n");
if (activeFlags->pid)
{
printf("PID %s\n", activeFlags->pid);
printf(" PID ProcessName State PPID SESSIONID\n");
getProcess(activeFlags->pid);
return 0;
}
else
{
printf("Also provide a PID\n");
return 0;
}
}
else
{
printf("No flag provided\n");
}
}
}
return 0;
}