-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshell_pinfo.c
More file actions
41 lines (40 loc) · 1.18 KB
/
shell_pinfo.c
File metadata and controls
41 lines (40 loc) · 1.18 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
#include "stdio.h"
#include "unistd.h"
#include "string.h"
#include "stdlib.h"
#include "sys/types.h"
#include "dirent.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "pwd.h"
#include "grp.h"
#include "time.h"
int pinfo(char **tokenlist)
{
char randstr[100],readstr[10004],randstr1[100],readstr1[1000];
char *argvs[100],*argvs1[100];
int pid =getpid();
if(tokenlist[1]==NULL)
{
sprintf(randstr,"/proc/%d/stat",pid);
sprintf(randstr1,"/proc/%d/exe",pid);
}
else
{
sprintf(randstr,"/proc/%s/stat",tokenlist[1]);
sprintf(randstr1,"/proc/%s/exe",tokenlist[1]);
}
int fd = open(randstr,O_RDONLY);
int fd1 = open(randstr1,O_RDONLY);
int numbyte = read(fd,readstr,10000);
int numbyte1 = readlink(randstr1,readstr1,1000);
char * wrd = strtok(readstr," ");
int i=0;
while(wrd!=NULL)
{
argvs[i++]=wrd;
wrd=strtok(NULL," ");
}
printf("pid:\t\t %s\nProcess Status: %s\nMemory: \t %s\nExecutable Path: %s\n",argvs[0],argvs[2],argvs[22],readstr1);
return 0;
}