-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpinfo.c
More file actions
executable file
·72 lines (63 loc) · 1.93 KB
/
pinfo.c
File metadata and controls
executable file
·72 lines (63 loc) · 1.93 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
#include "headers.h"
void pinfo(ll k, char *token[])
{
ll memory;
int f, f2;
char buf[1000000], file[10000], c, status, temp[100000];
pid_t pid;
if (k == 1)
pid = getpid(); //GETTING PID
else
pid = atoi(token[1]);
sprintf(file, "/proc/%d/stat", pid); //For status, memory
f = open(file, O_RDONLY);
f2 = open(file, O_RDONLY);
if (f < 0)
perror("Error: no such process exists\n");
else
{
FILE *fd;
fd = fopen(file, "r");
fscanf(fd, "%*d %*s %c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %lld %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d", &status, &memory);
fclose(fd);
printf("PID -- %d\n", pid);
printf("Process Status -- %c\n", status);
printf("Memory -- %lld\n", memory);
sprintf(file, "/proc/%d/exe", pid); // For executable path
int x = readlink(file, buf, sizeof(buf));
buf[x] = '\0';
// getcwd(cwd,sizeof(cwd));
x=0;
ll ii;
char buf2[100000];
if (strcmp(buf, pseudo_home) == 0)
strcpy(buf, "~");
else
{
for (ii = 0; pseudo_home[ii]; ii++)
{
if (pseudo_home[ii] != buf[ii])
{
// printf("char home %c\nchar cwd %c\n",pseudo_home[ii],cwd[ii]);
x = ii;
break;
}
}
// printf("Not equal at %d\n",x);
if (x == 0)
{
buf2[0] = '~';
ll p, j;
for (p = 1, j = ii; buf[j]; p++, j++)
{
// printf("%c",cwd[j]);
buf2[p] = buf[j];
}
buf2[p] = '\0';
}
else
strcpy(buf2, buf);
}
printf("Executable Path--- %s\n", buf2);
}
}