forked from AngelDevil1223/PROC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
57 lines (53 loc) · 1.12 KB
/
main.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
53
54
55
56
57
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "options.h"
#include "list.h"
#include "parser.h"
int main(int argc, char *argv[])
{
//declares flags, then initializes them using options.c
struct options *flags = (struct options *) malloc(sizeof(struct options));
int *processes;
if (initOptions(argc, argv, flags) == -1)
{
printf("%s\n", "Incorrect usage");
exit(EXIT_FAILURE);
}
//if p is not selected, uses list.c to create a list of pid
//then outputs information for them according to flags
if (flags->p == 0)
{
processes = generateProcessList();
int i = 0;
while (processes[i] != 0)
{
generatePrint(flags, processes[i]);
i++;
}
exit(EXIT_SUCCESS);
}
//otherwise it prints the information for the single pid. Also
//tests if given pid is a valid input.
else
{
processes = generateProcessList();
int i = 0;
int printed = 0;
while (processes[i] != 0)
{
if (processes[i] == flags->p)
{
generatePrint(flags, flags->p);
printed = 1;
}
i++;
}
if (printed == 0)
{
printf("PID DOES NOT EXIST\n");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
}