-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinfo.h
58 lines (57 loc) · 1.16 KB
/
pinfo.h
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
#ifndef ya
#define ya
void pin(int self){
FILE * fp=NULL;
char save[1024]={'\0'};
char str[1024] = "/proc";
char pid[20];
if(self!=1){
sprintf(pid,"/%s",input[1]);
}
else{
sprintf(pid,"/%d",getpid());
}
char buff[2000];
strcat(str,pid); // /proc/<pid>
strcpy(save,str); // /proc/<pid>
strcat(save,"/status"); // /proc/<pid>/status
strcat(str,"/exe"); // str = /proc/<pid>/exe
fp = fopen(save,"r");
if(!fp){
perror("File Not Opened");
return;
}
char store[200],scanner[200],proc_status[200],virt_mem[200];;
int len = 0;
while(1 == 1){
fgets(store,200,fp);
if(strstr(store,"State")){
sprintf(proc_status,"%s",store+7);
}
else if(strstr(store,"VmSize")){
sprintf(virt_mem,"%s",store+8);
break;
}
}
ssize_t ret = readlink(str, buff, 512);
if (ret < 0){
perror("readlink");
}
else
buff[ret] = 0;
printf("pid -- %d\n",getpid());
printf("Process Status -- %s",proc_status);
printf("Virtual Memory -- %s",virt_mem);
if(strstr(buff,cwd)!=NULL){
int cwdlen = strlen(cwd);
printf("Executable Path -- %s\n",buff+cwdlen);
}
else {
printf("Executable Path -- ~%s\n",buff);
}
if(fp){
fclose(fp);
fp = NULL;
}
}
#endif