-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinfo.c
40 lines (30 loc) · 919 Bytes
/
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
#include "main.h"
int pinfo(char **argv) {
char proc_path[400], info_path[500], sym_path[400], exe_path[500];
strcpy(proc_path, "/proc/");
strcat(proc_path, (argv[1]) ? argv[1] : "self");
strcpy(info_path, proc_path);
strcat(info_path, "/stat");
int fd = open(info_path, O_RDONLY);
if (fd == -1) {
perror("ush");
return 1;
}
char all[2048], **out;
read(fd, all, 2048);
out = tokenize_input(all, W_DELIM);
close(fd);
printf("pid -- %s\n", out[0]);
printf("Process Status -- %s\n", out[2]);
printf("Virtual Memory -- %s\n", out[22]);
strcpy(sym_path, proc_path);
strcat(sym_path, "/exe");
int len = readlink(sym_path, exe_path, 500);
if (len < 0) {
strcpy(exe_path, "Link Broken");
}
exe_path[len] = '\0';
printf("Executable Path -- %s\n", process_dir(exe_path));
free(out);
return 1;
}