48 lines
805 B
C
48 lines
805 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define BUFFER 270
|
|
|
|
char *cmdline(char *pid)
|
|
{
|
|
FILE *fp;
|
|
char path[BUFFER];
|
|
char temp[BUFFER * 100];
|
|
char *p;
|
|
unsigned char ch;
|
|
int i = 0;
|
|
|
|
memset(path, 0, BUFFER);
|
|
memset(temp, 0, BUFFER * 100);
|
|
snprintf(path, BUFFER, "/proc/%s/cmdline", pid);
|
|
|
|
if ((fp = fopen(path, "r")) == NULL) {
|
|
perror("fopen");
|
|
return 0;
|
|
}
|
|
|
|
while (!feof(fp)) {
|
|
ch = fgetc(fp);
|
|
if (ch == 0) {
|
|
temp[i] = ' ';
|
|
} else {
|
|
temp[i] = ch;
|
|
}
|
|
i++;
|
|
}
|
|
|
|
p = strrchr(temp, ' ');
|
|
temp[strlen(temp) - strlen(p)] = '\0';
|
|
printf("%s\n", temp);
|
|
|
|
fclose(fp);
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char *argv[], char **envlp)
|
|
{
|
|
cmdline(argv[1]);
|
|
|
|
return 0;
|
|
}
|