-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpinfo.c
More file actions
102 lines (81 loc) · 2.34 KB
/
pinfo.c
File metadata and controls
102 lines (81 loc) · 2.34 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
#include "headers.h"
#include "functions.h"
void pinfo(char *command)
{
if (debug)
printf("pinfo commmand = %s\n", command);
char *token = strtok(command, " \t");
if (debug)
printf("no more tok after this one - %s\n", token);
if (strcmp(token, "pinfo") != 0)
{
printf("this is not a pinfo command \n");
}
int pid = getpid();
char pidstring[MY_LEN];
sprintf(pidstring, "%d", pid);
token = strtok(NULL, " \t");
if (token != NULL)
{
strcpy(pidstring, token);
}
token = strtok(NULL, " \t");
if (token != NULL)
printf("Too many arguments for pinfo\n");
char pinfoPath[MY_LEN];
strcpy(pinfoPath, "/proc/");
strcat(pinfoPath, pidstring);
strcat(pinfoPath, "/stat");
FILE *fp = fopen(pinfoPath, "r");
if (fp == NULL)
{
printf("Invalid PID given: The path %s doesnt exist\n", pinfoPath);
return;
}
int processGroupId;
char temp[MY_LEN];
fscanf(fp, "%s", temp);
fscanf(fp, "%s", temp);
fscanf(fp, "%s", temp);
char processStatus[MY_LEN];
strcpy(processStatus, temp);
fscanf(fp, "%s", temp);
fscanf(fp, "%s", temp);
processGroupId = atoi(temp);
fclose(fp);
if (processGroupId == tcgetpgrp(0))
strcat(processStatus, "+");
strcpy(pinfoPath, "/proc/");
strcat(pinfoPath, pidstring);
strcat(pinfoPath, "/stat");
fp = fopen(pinfoPath, "r");
if (fp == NULL)
{
printf("Invalid PID given: The path %s doesnt exist\n", pinfoPath);
return;
}
for(int i = 0; i < 23 ;i++)
{fscanf(fp, "%s", temp);}
fclose(fp);
char processMemory[MY_LEN];
strcpy(processMemory, temp);
strcpy(pinfoPath, "/proc/");
strcat(pinfoPath, pidstring);
strcat(pinfoPath, "/exe");
fp = fopen(pinfoPath, "r");
if (fp == NULL)
{
printf("Invalid PID given: The path %s doesnt exist\n", pinfoPath);
return;
}
fscanf(fp, "%s", temp);
char processExe[MY_LEN];
strcpy(processExe, temp);
int x = readlink(pinfoPath, processExe, MY_LEN);
if (x == -1)
strcpy(processExe, "Does not exist");
printf("pid : %s\n", pidstring);
printf("prosess status : %s\n", processStatus);
printf("memory : %s {Virtual Memory}\n", processMemory);
printf("executable path : %s\n", Tildify(processExe));
}