forked from radiopushka/pmmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
79 lines (74 loc) · 2.15 KB
/
main.c
File metadata and controls
79 lines (74 loc) · 2.15 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
#include<stdio.h>
#include<dirent.h>
#include<ctype.h>
#include "filer.c"
#include "psaccess.c"
#include "definitions.h"
int main(int argn,char** args){
set_filter("kworker");
if(argn>1){
if(strcmp(args[1],"interactive")==0){
psdog();
return 0;
}
if(strcmp(args[1],"watchdog")==0){
if(argn==3){
set_filter(args[2]);
}
dumpps('l');
return 0;
}
if(strcmp(args[1],"h")==0){
printf("%s\n",HELP);
return 0;
}
}
if(argn==2){
if(isdigit(args[1][0])){
char* pathtocmd=filegroup("/proc/",args[1],"/status");
printfiledata(pathtocmd);
free(pathtocmd);
return 0;
}
}
struct dirent *dirinfo;
char* notshow="";
char* show="";
if(argn>2){
if(strcmp(args[1],"f")==0){
notshow=args[2];
}
if(strcmp(args[1],"r")==0){
show=args[2];
}
}
DIR *dir=opendir("/proc");
if(dir==NULL){ printf("no /proc acccess, terminating"); return 0;}
while((dirinfo=readdir(dir))!=NULL){
char* name=dirinfo->d_name;
if(isdigit(name[0])){
char* pathtocmd=filegroup("/proc/",name,"/cmdline");
char* pname=getprocessnamefromid(name);
if((strcmp(notshow,"")==0||strstr(pname,notshow))&&strcmp(show,"")==0){
printf("id: %s | name: %s",name,pname);
printf(" | launch command: ");
printfiledata(pathtocmd);
free(pathtocmd);
printf("\n");
}else if(strcmp(show,"")!=0&&!strstr(pname,show)){
printf("id: %s | name: %s",name,pname);
printf(" | launch command: ");
printfiledata(pathtocmd);
free(pathtocmd);
printf("\n");
}
free(pname);
//printf("type pmmanager h for help option \n");
}
//printf("type pmmanager h for help option \n");
//free(name);
}
printf("type pmmanager h for help option \n");
closedir(dir);
return 0;
}