-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinfo.c
90 lines (90 loc) · 1.57 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/utsname.h>
#include "function.h"
void pinfo(char **pinfoPid)
{
int flag = 0, pid1, i, j, h = 0;
char string4[1000], string5[1000], ex[1000];
char *pid, *temp, *check, *mem;
pid = (char *)malloc(1000 * sizeof(char));
temp = (char *)malloc(1000 * sizeof(char));
check = (char *)malloc(1000 * sizeof(char));
mem = (char *)malloc(1000 * sizeof(char));
if(pinfoPid[1] != NULL)
{
strcpy(pid, pinfoPid[1]);
flag = 1;
}
else
{
pid1 = getpid();
j = pid1;
while(j != 0)
{
h++;
j = j / 10;
}
j = pid1;
for(i = h - 1; i >= 0; i--)
{
temp[i] = (j % 10 + '0');
j = j / 10;
}
temp[h] = '\0';
}
if(pinfoPid[1] != NULL)
{
printf("pid -- %s\n", pid);
}
else
{
printf("pid -- %s\n", temp);
}
printf("Process Status -- ");
fflush(stdout);
strcpy(check, "ps -o stat= -p ");
if(pinfoPid[1] != NULL)
{
strcat(check, pid);
}
else
{
strcat(check, temp);
}
pinfoPid = tokenize1(check, " ");
execute(pinfoPid);
printf("Memory --");
fflush(stdout);
strcpy(mem, "ps -o vsz= -p ");
if(flag == 1)
{
strcat(mem, pid);
}
else
{
strcat(mem, temp);
}
pinfoPid = tokenize1(mem, " ");
execute(pinfoPid);
strcpy(string4, "/proc/");
if(flag == 1)
{
strcat(string4, pid);
}
else
{
sprintf(ex, "%d", pid1);
strcat(string4, ex);
}
strcat(string4, "/exe");
readlink(string4,string5, sizeof(string5)-1);
printf("Executable Path -- %s\n", string5);
}