-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinfo.c
56 lines (53 loc) · 1.12 KB
/
pinfo.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
#include "headers.h"
void pinfo(char *pid)
{
char path[100], exepath[100], line[100], *p;
strcpy(path, "/proc/");
strcpy(exepath, "/proc/");
if(!pid)
{
sprintf(path + strlen(path), "%ld", (long) getpid());
sprintf(exepath + strlen(exepath), "%ld", (long) getpid());
printf("pid - %d\n",getpid() );
}
else
{
strcat(path, pid);
strcat(exepath, pid);
printf("pid - %s\n",pid);
}
strcat(path, "/status");
strcat(exepath, "/exe");
FILE* fd = fopen(path,"r");
if(fd <= 0)
{
printf("No such process\n");
return;
}
while(fgets(line, 100, fd))
{
if(strncmp(line, "State:", 6) != 0)
continue;
p = line + 7;
while(*p == ' ') ++p;
printf("Process Status - %s", p);
break;
}
while(fgets(line, 100, fd))
{
if(strncmp(line, "VmSize:", 6) != 0)
continue;
p = line + 7;
while(*p == ' ') ++p;
printf("Memory - %s", p);
break;
}
char *out = realpath(exepath,NULL);
if(out == NULL)
{
printf("Permission denied\n");
return;
}
printf("Executable path - %s\n",out);
fclose(fd);
}