-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.c
More file actions
66 lines (54 loc) · 2.12 KB
/
Copy pathsearch.c
File metadata and controls
66 lines (54 loc) · 2.12 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
#include "search.h"
#include <ctype.h>
int search(char *filename)
{
DIR *dir = opendir("/proc");
struct dirent *x;
if (dir == NULL)
return -1;
while ((x = readdir(dir)) != NULL)
{
pid_t pid = atoi(x->d_name);
char path[256];
char name[256];
snprintf(path, sizeof(path), "/proc/%d/comm", pid);
FILE *fp = fopen(path, "r");
if (fp == NULL)
continue;
if (fgets(name, sizeof(name), fp) != NULL)
{
name[strcspn(name, "\n")] = '\0';
if (strcmp(name, filename) == 0)
{
fclose(fp);
closedir(dir);
return pid;
}
}
fclose(fp);
}
closedir(dir);
return -1;
}
void banner(void)
{
printf(
"████████╗██████╗ █████╗ ██████╗███████╗██╗████████╗\n"
"╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██╔════╝██║╚══██╔══╝\n"
" ██║ ██████╔╝███████║██║ █████╗ ██║ ██║ \n"
" ██║ ██╔══██╗██╔══██║██║ ██╔══╝ ██║ ██║ \n"
" ██║ ██║ ██║██║ ██║╚██████╗███████╗██║ ██║ \n"
" ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚══════╝╚═╝ ╚═╝ \n"
"\n"
"=============================================================\n"
" Linux Process Inspector / TraceIt\n"
"=============================================================\n"
" Author : TraceByte\n"
" Version: 1.0\n"
" Platform: Linux\n"
"-------------------------------------------------------------\n"
" Search running processes\n"
" Read information from /proc/<pid>\n"
" Display cmdline, exe, cwd, root, status, memory...\n"
"=============================================================\n\n");
}