-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproclore.c
More file actions
119 lines (116 loc) · 3.04 KB
/
proclore.c
File metadata and controls
119 lines (116 loc) · 3.04 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "./include/headers.h"
void proclore(char *input)
{
if (strcmp(input, "proclore") == 0)
{
int pid = getpid();
char *path = (char *)malloc(sizeof(char) * 50);
for (int i = 0; i < 50; i++)
path[i] = '\0';
sprintf(path, "/proc/%d/stat", pid);
FILE *fptr = fopen(path, "r");
if (fptr == NULL)
{
fprintf(stderr,RED"file didn't open\n"RESET);
return;
}
char buff[100];
int count = 0;
while (fscanf(fptr, "%s", buff))
{
count++;
if (count == 1)
printf("PID : %s\n", buff);
if (count == 3){
printf("Process Status : %s+\n", buff);
}
if (count == 5)
printf("Process Group : %s\n", buff);
if (count == 23)
{
printf("Virtual Memory : %s\n", buff);
break;
}
}
fclose(fptr);
char executable[500];
for (int i = 0; i < 500; i++)
executable[i] = '\0';
char exe[50];
sprintf(exe, "/proc/%d/exe", pid);
readlink(exe, executable, 499);
printf("Executable Path : %s\n", executable);
return;
}
char second[20];
for (int i = 0; i < 20; i++)
{
second[i] = '\0';
}
int flag = 0;
int pos = 0;
int size = strlen(input);
for (int i = 0; i < size; i++)
{
if (flag == 1)
{
second[pos++] = input[i];
}
if (input[i] == ' ')
flag = 1;
}
int OGgroupid=getpgrp();
second[pos] = '\0';
int pid = atoi(second);
char *path = (char *)malloc(sizeof(char) * 50);
for (int i = 0; i < 50; i++)
path[i] = '\0';
sprintf(path, "/proc/%d/stat", pid);
FILE *fptr = fopen(path, "r");
if (fptr == NULL)
{
fprintf(stderr,RED"file didn't open\n"RESET);
return;
}
char buff[100];
int count = 0;
char** resu=(char**)malloc(sizeof(char*)*10);
for(int i=0;i<10;i++)
resu[i]=(char*)malloc(sizeof(char)*100);
for(int i=0;i<10;i++)
resu[i][0]='\0';
while (fscanf(fptr, "%s", buff))
{
count++;
if (count == 1)
catenate(resu[0],buff,0);
if (count == 3){
catenate(resu[1],buff,0);
}
if (count == 5)
catenate(resu[2],buff,0);
if (count == 23)
{
catenate(resu[3],buff,0);
break;
}
}
fclose(fptr);
printf("Pid : %s\n",resu[0]);
int gid=atoi(resu[2]);
if(gid==OGgroupid)
printf("Process Status : %s+\n",resu[1]);
else{
printf("Process Status : %s\n",resu[1]);
}
printf("Process Group : %s\n",resu[2]);
printf("Virtual Memory : %s\n",resu[3]);
char executable[500];
for (int i = 0; i < 500; i++)
executable[i] = '\0';
char exe[50];
sprintf(exe, "/proc/%d/exe", pid);
readlink(exe, executable, 499);
printf("Executable Path : %s\n", executable);
return;
}